TVirtualTable maintaining AutoInc fields between sessions

Discussion of open issues, suggestions and bugs regarding Virtual Data Access Components for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
JimMellish
Posts: 8
Joined: Wed 06 Mar 2013 21:48

TVirtualTable maintaining AutoInc fields between sessions

Post by JimMellish » Tue 11 May 2021 08:56

Is it possible to maintain autoinc values between closing and opening the virtual table. I am running the following code:

Code: Select all

  VirtualTable.FieldDefs.Add('IntField', ftInteger);
  VirtualTable.FieldDefs.Add('AutoField', ftAutoInc);

  VirtualTable.Open;

  VirtualTable.Append;
  VirtualTable.FieldByName('IntField').AsInteger := 7;
  VirtualTable.Post;

  VirtualTable.Append;
  VirtualTable.FieldByName('IntField').AsInteger := 8;
  VirtualTable.Post;

  VirtualTable.SaveToFile('Test.bin');
  VirtualTable.Close;

  {--------------------------------------------------}

  VirtualTable.LoadFromFile('Test.bin');
  VirtualTable.Open;

  VirtualTable.Append;
  VirtualTable.FieldByName('IntField').AsInteger := 9;
  VirtualTable.Post;

  VirtualTable.First;
  while not VirtualTable.Eof do
    begin
      Memo.Lines.Add (VirtualTable.RecNo.ToString + ' ' +
                      VirtualTable.FieldByName('IntField').AsString + ' ' +
                      VirtualTable.FieldByName('AutoField').AsString);
      VirtualTable.Next;
    end;
1) Define an autoinc field and open the table.
2) Post two new records.
3) Save the table and close it.

4) Open the table and load it
5) Post a new record
6) List the data contained in the table.

I would expect to see
1 7 1
2 8 2
3 9 3

I am getting
1 7 1
2 8 2
3 9 1

Post Reply