Mega Code Archive

 
Categories / Delphi / ADO Database
 

Reset Paradox Auto incremental field

Title: Reset Paradox Auto-incremental field Question: How can I easily reset an auto-incremental field in a Paradox table? Answer: If theres anyone who still use Paradox files, this is a good tip: Sometimes, we have to erase all records of a table that has auto-increment fields. When you try to append some new records to this table, the auto-incremental field does not reset itself. So how can we reset this number ? The solution: this simple function expects the Paradox table filename and the new counter and returns if the operation is sucessfull. function ResetAutoInc(FileName: TFileName; NewValue:Longint): Boolean; begin with TFileStream.Create(FileName, fmOpenReadWrite) do try Result := (Seek($49, soFromBeginning) = $49) and (Write(NewValue, 4) = 4); finally Free; end; end; I tested this function with Paradox 7 files. If someone has older formats please test it and put a note on this article. Thanks to my colleague Isnard who gave me this valueable tip. Health and Freedom, Josir.