I am having an exception when editing a record in a virtual table after adding a field in the virtual table.
Please advise how I can update the virtual table structure and also being able to edit the record.
The code is below. Using Lazarus with Unidac 6.2.10.
Code: Select all
procedure TVirtualPop.DoRun;
var
Source: TVirtualTable;
begin
Source := TVirtualTable.Create(nil);
Source.FieldDefs.Add('ID', ftInteger);
Source.Open;
Source.AppendRecord([1]);
Source.Close;
Source.FieldDefs.Add('A', ftString); //works without this line
Source.Open;
writeln('NmbFields:' + IntToStr(Source.FieldCount)); //prints 2
try
with Source do
begin
if Locate('ID', 1, []) then
begin
Edit;
FieldByName('ID').AsInteger := 100;
Post;
end;
end;
except
on E: Exception do
begin
writeln('Error:' + E.Message); //prints list index out of bounds
end;
end;
Source.Free;
Terminate;
end;