PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Help on HReadSeekFirst
Help on HReadSeekFirst
Débuté par guest, 06 déc. 2010 18:08 - 10 réponses
Posté le 06 décembre 2010 - 18:08
Hi
I am doing an HReadSeekFirst(HWModels, ModelID, model_id). If HOUT is true I know the record is not in the database yet and I do an HAdd(HWModels). This is how I add data to the table. The ModelID field is a unique index in the table. The problem is that sometimes when the table does not have a record for a ModelID HOut while equal false and the record will not be added to the database, when it really should be because the ModelID I am using to do the seek is not in the HWModels database. But WD thinks the record is already in the database. And does not go into my IF HOut(HWModels) section of code. Does anybody have a clue as to what on earth is happening to where WD thinks a record is in the database when it is not. I am using HReadSeekFirst instead of HReadSeek. When I get back to the office I will try the HReadSeek since there can only be one record with that ModelID, but I don't think there will be any difference. But any help I can get will be greatly accepted.
Thanks
Posté le 06 décembre 2010 - 18:07
Hi John,
For your case, you should use Hfound() rather than Hout(). See http://doc.windev.com/en-US/… for further info.
Regards,
-Marc
Posté le 06 décembre 2010 - 18:08
Hallo John, I use without problems :
if not hreadseekfirst(...) then hadd(..) end
Posté le 06 décembre 2010 - 18:34
Thanks Marc, I don't know how many times you have helped me out but I do really appreciate it.
Also if you have time could you tell me why HFound() worked and HOut() didn't.
Thanks again
Posté le 06 décembre 2010 - 18:34
Thanks Christopher for your time, Marc's way worked perfect. I am thankful for the time you gave me.
Posté le 06 décembre 2010 - 19:27
Hi John
- Hfound tells you if a record was FOUND, ie works on a SEEK operation.
- Hout tells you if you EXITED your dataset, ie for a BROWSE operation (hreadfirst/next, by example)
Best regards
Posté le 06 décembre 2010 - 22:53
Say you have a file:
Arie
Fabrice
John
If you search for Peter HFound will return FALSE and HOut will return TRUE.
If you search for Christoph HFound will return FALSE and HOut will return FALSE, because the recordpointer will be on "Fabrice" and the search will end there.
HOut has no meaning in search operations.
Posté le 06 décembre 2010 - 22:54
Hi,
the surefire way
IF NOT HSeek(MyFile,MyUniqueKey,MySearchArgument,hIdentical) THEN
// Set fields of MyFile either by a ScreenToFile(..) or by
MyFile.MySearchArgument = ...
MyFile.MyStringData = ...
.....
IF NOT HAdd(MyFile) THEN
HError(hErrCurrent),HErrorInfo(hErrFullDetails))
END
END

With HyperFile you always have to think about two things:
1 - where is the file pointer?
2 - what's in the file buffer?
HReadSeek.. has always the potential to change the contents of your file buffer. I routinely set the file buffer's fields straight before doing the HAdd - this assures me that nothing will change the file buffer and only those data will go into the file which I wanted to go there. HSeek(..) will not change the file buffer's contents but it will move the file pointer if HFound(MyFile) is true. The file pointer is irrelevant for an HAdd(..) operation, but is very important when doing an HModify(..).
Regards, Guenter
Posté le 06 décembre 2010 - 23:16
Hi,
if you use HFilter(FILE,...) somewhere in the application bevor the HReadSeekFirst(FILE,...) you have to deactivate the Filter with HDeactivateFilter(FILE). Otherwise the HReadSeekFirst will only find Records within the Filtercondition.
Best Regards
Konrad Filser
Posté le 06 décembre 2010 - 23:16
Thanks Konrad but I don't use a filter anywhere in my program. I am real curious why HFound() works and HOut() doesn't. Thanks again for your time.
Posté le 07 décembre 2010 - 10:26
Hi,
HOut(MyFile) indicates only that your program tried to move the file pointer outside of the boundaries of the file! Trying to move the file pointer to less than record #1 or farer than the last record in the file will result in HOut(MyFile) to be true.
HFound(MyFile) indicates whether an HSeek.. or HReadSeek.. operation succeeded or not - the 'seeked' record has been found or not. The case HFound(MyFile) = False therefore doesn't necessarily mean that the file pointer had been moved outside of the file boundaries.
Regards, Guenter