TMyQuery and populating a TTreeView

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Bryan
Posts: 13
Joined: Fri 09 Feb 2007 16:02

TMyQuery and populating a TTreeView

Post by Bryan » Sun 18 Feb 2007 18:45

Hello,

I'm trying to populate a TTreeView with the results of a TMyQuery.
The query returns a single list of items (1 field)

Code: Select all

  for x := 0 to MyQuery1.RecordCount - 1 do
    TreeView1.Items.AddChild(MainNode,  MyQuery1.FieldByName('storm_id')[x].AsString);
Obviously this will not compile.... so is there a way.
This seems so simple, but I've been pounding my head for over 2 hours.

Thanks!
Bryan

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Mon 19 Feb 2007 07:44

You are trying to access a recordset as an array of records. This is not correct. Try to use the following code:

Code: Select all

  MyQuery1.First;
  for x := 0 to MyQuery1.RecordCount - 1 do begin
    TreeView1.Items.AddChild(MainNode,  MyQuery1.FieldByName('storm_id').AsString);
    MyQuery1.Next;
  end;
Please read more about working with datasets in the Delphi Help documentation.

Bryan
Posts: 13
Joined: Fri 09 Feb 2007 16:02

Post by Bryan » Mon 19 Feb 2007 13:33

Thanks for your help. I finally figured it out after another hour... :) Your code example is a little more streamlined so I'll use it instead of my attempt.

Thanks!
Bryan
Antaeus wrote:You are trying to access a recordset as an array of records. This is not correct. Try to use the following code:

Code: Select all

  MyQuery1.First;
  for x := 0 to MyQuery1.RecordCount - 1 do begin
    TreeView1.Items.AddChild(MainNode,  MyQuery1.FieldByName('storm_id').AsString);
    MyQuery1.Next;
  end;
Please read more about working with datasets in the Delphi Help documentation.

Post Reply