Page 1 of 1

On added field update is not returned

Posted: Tue 10 May 2016 20:38
by tudi_x
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;       

Re: On added field update is not returned

Posted: Wed 11 May 2016 08:41
by AlexP
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);

Re: On added field update is not returned

Posted: Wed 11 May 2016 13:19
by tudi_x
Got it!
Thank you.

Re: On added field update is not returned

Posted: Thu 12 May 2016 05:13
by AlexP
Hello,

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