Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 10 Monaten, 3 Wochen
Letzter Beitrag:
vor 10 Monaten, 2 Wochen
Beteiligte Autoren:
GuenterP, Fabrice Harari, ICI, Piet van Zanten, Art Bonds, JP, DarrenF, Stefan Bentvelsen, Frans, Joris, Binod Lohani

Question on HReadSeekFirst / HFound()

Startbeitrag von Binod Lohani am 01.09.2017 02:34

Hello Gang ! Namaste !!
Here are two piece of code :

// Find the first record for which
// the CUSTOMER name is MOORE
Error("Customer not found")
// Continue the process on the customer named MOORE

IF HReadSeekFirst(CUSTOMER, NAME, "MOORE") = False then
Error("Customer not found")
// Continue the process on the customer named MOORE

What is the difference between these two codes ?? Should I call HFound() after HReadSeekFirst / HReadSeekLast ??
Which is Better Practice ??


Hi Binod,

I use the second method a lot. It is shorter and it works like it should.
It works imho the same as calling HFound().

von Stefan Bentvelsen - am 01.09.2017 06:08
I use first method. Like to have clear code, easy to read. Both situations are correct. You use what ever you prefer .

von ICI - am 01.09.2017 06:15

I think this is shorter and easy to read

IF HReadSeekFirst(CUSTOMER, NAME, "MOORE") then
/ Continue the process on the customer named MOORE
Error("Customer not found")

von Frans - am 01.09.2017 08:14
Or even shorter :

Error("Customer not found")
// Continue the process on the customer named MOORE

von Joris - am 01.09.2017 09:03
I think Frans might be the winner in the processing time efficiency stakes, but I agree with ICI, I too use the "easy to read and maintain" syntax. To me saving billionth of a second in processing time in a business processing application is neither "here-nor-there"; maintainability is king! ...although if the READ statement is in a loop might change things, but only slightly ...discuss :xcool:

von DarrenF - am 01.09.2017 10:25
If we want to be so precise in mm I use this combination of few codes from there:

I prefer this:

sName is string = "MOORE" (or EDT_Name)
HReadSeekFirst(CUSTOMER, NAME, sName)
IF HFound(CUSTOMER)=False then
Error("Customer not found")
// Continue the process on the customer named MOORE

I want to read whole process like we talk in real life, how it can be closer.

von ICI - am 01.09.2017 23:12
My 2 cents,

if hreadseek(F_Customer,asName,"MOORE",hidentical)=false then
//test if DB error and manage or if simply not found
//Manage customer moore

Be aware that if yo don't use the hidentical option, then you will find MOOREEEEE when looking for MOORE.

Also, I do NOT use hreadseekFIRST if I'm not going to loop on a hreadNEXT afterwards. With hreadseek, I'm not looking for the first of a series, I'm looking for an EXACT match (hence the hidentical option).

Best regards

von Fabrice Harari - am 02.09.2017 12:54
I have always followed the maxim that you need to design and code with the thought that the next developer that maintains your code is a homicidal maniac that knows where you live.

von Art Bonds - am 02.09.2017 14:36
Hello Art,

now, that one, I want to publish as a citation on the front page of my web site :-)

Can I? Can I? Please!Please!Please!

:xcool: :cheers: :D

von Fabrice Harari - am 02.09.2017 22:10

I agree with you. I also for many years now write code as close to how I can speak it so that it becomes as obvious as possible. I rather write more code and many more comments than try and be a little bit faster in typing or execution. ... thought I was the only one lol! :)

von JP - am 03.09.2017 05:25
Hi Art, I agree on that, definitely!

von GuenterP - am 03.09.2017 05:44
Hi Fabrice,

I have to disagree on this one. The Help says:

HReadSeekFirst (Function)
Positions on the first record of a data file whose value for a specific item is strictly equal to a sought value (exact-match search). The record is read and the corresponding HFSQL variables are updated.

I have used IF (NOT) HreadSeekFirst for as long as I can remember and never had any problems.
The hIdentical constant is mentioned only for HreadFirst.

Kind regards,

von Piet van Zanten - am 03.09.2017 08:59
Hi Piet, you're right!

However, there is a small but important difference between HReadSeekFirst(...) and the much older HReadSeek(.... [,hidentical]) !

HReadSeekFirst(..) positions on the first record / key within a set of identical keys. Several HReadNext(..) after that are guaranteed to find all of the records containing exactly that key.

HReadSeek(... , hidentical) finds any record within that set of identical keys - not necessarily the really first one of the set - and a few HReadNext(...) after that will NOT find all of the records with the same key, reading just ends whenever a record with a key greater than the sought one appears.

This had been one of my demonstrable problems with HReadSeek(...) in early WINDEV 5.5 programs, the answer to that had been HReadSeekFirst(...)!

It may be, I did not test it, that HReadSeekFirst(...) and HReadSeek(..., hidentical) are working the same way by now.

von GuenterP - am 03.09.2017 16:55
Hi Guenter,

Indeed, this stuff is all still there for compatibility reasons.
I don't remember ever using HReadFirst anymore, perhaps in the days there were no client server and queries yet.
I'm only using HReadSeekFirst to find unique identifiers, for the rest I think queries are the better option.

Kind regards,

von Piet van Zanten - am 04.09.2017 09:19
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.