On added field update is not returned

Discussion of open issues, suggestions and bugs regarding Virtual Data Access Components for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
tudi_x
Posts: 15
Joined: Thu 09 Jul 2015 17:14
Location: Oklahoma

On added field update is not returned

Post by tudi_x » Tue 10 May 2016 20:38

Hi Support!
Using the April 25th version on Lazarus 1.6 32b FPC 3 on Windows 7 64b, continuing the added field, please note that adding a value on the field does not look like it is updated as per the below code.

Please advise.

Code: Select all

procedure TVirtualPop.DoRun;
  var
    Source: TVirtualTable;

  begin
    Source := TVirtualTable.Create(nil);
    Source.FieldDefs.Add('ID', ftInteger);
    Source.FieldDefs.Add('AGE', ftInteger);
    Source.Open;
    Source.AppendRecord([1]);
    Source.Close;
    Source.FieldDefs.Add('A', ftString);
    Source.Open;
    writeln('NmbFields:' + IntToStr(Source.FieldCount));

    try
      with Source do
      begin
        if Locate('ID', 1, []) then
        begin
          Edit;
          FieldByName('ID').AsInteger := 101;
          FieldByName('AGE').AsInteger := 25;
          FieldByName('A').AsString := 'TEST';
          Post;

          writeln(FieldByName('ID').AsString);  //returns 101
          writeln(FieldByName('AGE').AsString); //returns 25
          writeln(FieldByName('A').AsString);   //returns empty
        end;
      end;
    except
      on E: Exception do
      begin
        writeln('Error:' + E.Message);    //prints list index out of bounds
      end;
    end;       

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: On added field update is not returned

Post by AlexP » Wed 11 May 2016 08:41

Hello,

This is correct behavior, since you haven't specified the string field size, and in the standard method TFieldDefs.Add (the DB module) the default value of the size parameter is 0. To get the correct behavior, you should add the such fields as follows:

Code: Select all

Source.FieldDefs.Add('A', ftString, 20);

tudi_x
Posts: 15
Joined: Thu 09 Jul 2015 17:14
Location: Oklahoma

Re: On added field update is not returned

Post by tudi_x » Wed 11 May 2016 13:19

Got it!
Thank you.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: On added field update is not returned

Post by AlexP » Thu 12 May 2016 05:13

Hello,

You are welcome. Feel free to contact us if you have any further questions.

Post Reply