Home Delphi TAdsQuery is NOT static. How to make it static
Reply: 0

Delphi TAdsQuery is NOT static. How to make it static

user1342
1#
user1342 Published in April 26, 2018, 5:15 pm

I've ran into this issue before, and know how to get around it, but I'd like to know if there is a property I'm missing, or better way. My solution is to get a record count, then iterate by the count, vs looking for EOF.

Is there a better way?

What happens is the query result re-reads the Source.dbf AFTER the post. You never reach EOF, and the loop is infinite.

Consider the following code. For Simplicity, Source.dbf is a single record table, with a single field (named Field1). Field1 in Record 1 has the value of '123'.

procedure TForm1.Button1Click(Sender: TObject);
begin
  CreateSourceTable;
  CreateQuery;

  while not Qry.EOF do
  begin
    tblSource.Append;
    tblSource.FieldByName('Field1').AsString := '123';
    tblSource.Post;
    Qry.Next;
  end;
end;

procedure TForm1.CreateQuery;
begin
  Qry := TAdsQuery.Create(self);
  Qry.TableType := ttADSCdx;
  Qry.DatabaseName := 'c:\project\windows\tools\StaticQuery';
  Qry.SQL.Add('Select * from Source');
  Qry.SQL.Add('where Field1 = ''123''');
  Qry.Open;
end;

procedure TForm1.CreateSourceTable;
begin
  tblSource := TAdsTable.Create(self);
  tblSource.DatabaseName := 'c:\project\windows\tools\StaticQuery';
  tblSource.TableName := 'Source.dbf';
  tblSource.TableType := ttADSCdx;
  tblSource.Open;
end;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.324256 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO