Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 5 Jahren, 1 Monat
Letzter Beitrag:
vor 5 Jahren, 1 Monat
Beteiligte Autoren:
Yogi Yang, stefan.kern, DerekT

Use HRetrieveRecord to get the ID of last inserted record?

Startbeitrag von Yogi Yang am 04.07.2013 14:40

The function HRetrieveRecord retrieves the last inserted record. Will this function work properly in HFCS also when multple users are saving data to same file at a time?

Can we just get the ID of the last inserted record directly?

I am asking this because I don't have such an environment on hand, to test, where I am working.


Yogi Yang


If I need the ID I do it like this:

bRes = HADD(Customer)
If bRes = TRUE
nNewID is int = customer.Customer_id
INFO("Shit happens")



von stefan.kern - am 04.07.2013 18:32

But in this case if we are in a Multi User environment and using HFCS the record you inserted may not be the last record so the ID that you get may be invalid.

von Yogi Yang - am 06.07.2013 07:23

If we are using the software in multi user environment (HFCS) then you code may not necessarily return a valid ID.

von Yogi Yang - am 06.07.2013 07:25
Hi Yogi,

no, I will find the ID of the record which was added by one specific client.
But I thing hretrievrecord does also find the actual record, so the result should be the same, or am I wrong???


Maybe hreadlast() before extracting the string, or select max (my_ID) could help??

Best Regards


von stefan.kern - am 06.07.2013 13:29

Hadd places the new record in the buffer - the id retrieved by MyFile.RecordID following the Hadd will always belong to the current record.

From the Help......
The added record becomes the current record. The automatic identifier is automatically filled. By default, the current browse is not affected.

I know you think that this group is your best way forward but I do think you should spend more time on the tutorials and reading the Help - that way you not only get the information you need but will also gain a lot of associated knowledge IMHO.

von DerekT - am 06.07.2013 22:07

I have read the docs and am stuck here. Initially while I was exploring WD I was just posting questions as I ran into them without much of investigation as I was trying to relate typical problems in WD with my Delphi and VB6 experience. But now I check the help and if I cannot find a solution then only I am post here.

I check the HRetrive record docs and all that I can say is that it is way to get the current record in a variable in one single call instead of reading each field one by one. And this record comes as a string.

Now back to my problem:

I am not able to get the ID of the last inserted record in a multi-user environment reliably and this is corrupting the data.

All the suggestions that are given here are valid and usable for a single user system running on HF Classic but not in case of HFCS.


Yogi Yang

von Yogi Yang - am 07.07.2013 05:24
I have never experienced the problems you seem to be having using the method I described when using this against HF, HFCS, MySQL etc.
Nor do I recall any such issue being raised on the group in the past.

A bit more info would be helpful...
What are you using the 'last id' for ?
Can you provide a code example of what you are doing ?
At what stage in your stress testing does this actually happen ?
Can you recreate the problem at will or is it intermittent ?

von DerekT - am 07.07.2013 08:26
Hi Yogi,

if you use an autoinc ID, you should get the last id with:

dsID is data source
sSQL is string = select max (id_ofMyTable) as maxID from myTable

von stefan.kern - am 07.07.2013 09:59
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.