coder007
coder007

Reputation: 39

Delphi: Save the output of a select statement in a Stringlist

I have following Select Statement: SHOW TABLES.

The output is:

table1
table2
table3
...

I want to save the resultset to a TStringList. How can I do that?

I have searched on the Internet but found only solutions where the field name is known.

procedure TForm1.FormCreate(Sender: TObject);
var
  s:string;
  list : tstringlist;
begin
  FDQuery1.open('show tables');

  with FDQuery1 do
  begin
    while not EOF do
    begin
      //list.Add();
      Next;
    end;
  end;

  ListBox1.Items.AddStrings(list);
end;

Upvotes: 0

Views: 1102

Answers (1)

MartynA
MartynA

Reputation: 30735

If you don't know the field name, try

List.Add(FDQuery1.Fields[0].AsString);

or

s := FDQuery1.Fields[0].AsString;
List.Add(s);

That will add the string value of the first column in the current row of the result set returned by FDQuery1.

Btw you can get the field name (aka columnname of the query) of the field by

s := FDQuery1.Fields[0].FieldName;

Upvotes: 5

Related Questions