Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate List with Query Names

Status
Not open for further replies.

tamara3776

Programmer
Apr 6, 2004
18
US
Hi All,
I am a newcomer to delphi and am looking for some help. I am wondering if there is a way to add the names of TQuery objects to a list box. I have several Queries in one application and would like a central area to see the queries and eventually the SQL behind them.

Please let me know if you can help. It would much appreciated.

Thanks in advance
 
If all the TQueries are on a form:

To add names of queries to a listbox.

Code:
procedure TForm1.LoadButtClick(Sender: TObject);
var
  i:integer;
begin
  ListBox1.Items.Clear;
  for i:=0 to ComponentCount-1 do
    if(Components[i] is TQuery)then
      ListBox1.Items.Append(Components[i].Name);
end;

To see the SQL, say on double click

Code:
procedure TForm1.ListBox1DblClick(Sender: TObject);
var
  i:integer;
  LQueryName:string;
begin
  if(ListBox1.ItemIndex<0)then
    Exit;

  LQueryName:=ListBox1.Items[ListBox1.ItemIndex];

  for i:=0 to ComponentCount-1 do
    if(Components[i].Name=LQueryName)then
    begin
      Memo1.Lines.Assign(TQuery(Components[i]).SQL);
      Exit;
    end;
end;

Is this what you are after?
Simon
 
That is exactly what I am looking for. Thank you so much.
 
One other question.
If I wanted to select multiple items in my list and have them all show in the memo field how would I go about this. This is what I have so far:

var
i : integer;
begin
memSQL.Clear;
if(lstQuery.ItemIndex>=0)then
begin
if lstQuery.SelCount > 0 then
begin
for i := 0 to lstQuery.Items.Count - 1 do
begin
if(lstQuery.Selected)then
begin
memSQL.Lines.Assign(TQuery(Components).SQL);
end;
end;
end;
end;

I know the line where it gets added to the memo field is incorrect and have tried many things but nothing is seeming to work. If you can help out once again I would greatly apprecite it. Thanks
 

memSQL.Lines.AddStrings(TQuery(Components).SQL);

or

memSQL.Lines.Append(TQuery(Components).SQL.Text);

Check out Delphi help for TStrings.


An aside:
if(lstQuery.ItemIndex>=0)then
begin
if lstQuery.SelCount > 0 then

Both these conditions seem unnecessary. If
lstQuery.Items.Count=0
then
for i := 0 to lstQuery.Items.Count - 1 do
will execute zero times.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top