Board index » delphi » Using TStringList and TIBQuery result set

Using TStringList and TIBQuery result set

I am trying to figure out how to get data from a TIBQuery component into a
TStringList object.  I want to be able to do the following statement:

select FULL_NAME from PERSON ;

and have it return the full name of every person listed in my PERSON table.
I want to take the result set and put it into a TStringList.

I then pass that TStringList to the calling method, which then uses the
AddStrings method to add the strings in the TStringList object into a TMemo,
TComboBox, or similar components.

Can someone help me with this?  I'm also looking for some good reference
material.

My normal email is mattkoso...@hotmail.com.

 

Re:Using TStringList and TIBQuery result set


var
  NameList:        TStringList;
begin
  IBQuery1.Open;
  NameList := TStringList.Create;
  try
    while not IBQuery1.EOF do
      NameList.Add(IBQuery1.FieldByName('FullName').AsString);
    IBQuer1.Close;
  finally
    NameList.Free;
  end;

--
Bill
(TeamB cannot answer questions received via email)

Re:Using TStringList and TIBQuery result set


In article <3bc06066$1_1@dnews>, "Bill Todd \(TeamB\)"

Quote
<bill.nos...@dbginc.com> wrote...
> var
>   NameList:        TStringList;
> begin
>   IBQuery1.Open;
>   NameList := TStringList.Create;
>   try
>     while not IBQuery1.EOF do
       begin
>       NameList.Add(IBQuery1.FieldByName('FullName').AsString);

        IBQuery1.Next;
      end;
Quote
>     IBQuer1.Close;
>   finally
>     NameList.Free;
>   end;

Re:Using TStringList and TIBQuery result set


Details Details <g>.  Actually if this is all you will be doing, use an IBSQL
instead (still keeping Phil's correction and Bill's code).

Quote
Phil Shrimpton wrote:

> In article <3bc06066$1_1@dnews>, "Bill Todd \(TeamB\)"
> <bill.nos...@dbginc.com> wrote...

> > var
> >   NameList:        TStringList;
> > begin
> >   IBQuery1.Open;
> >   NameList := TStringList.Create;
> >   try
> >     while not IBQuery1.EOF do
>        begin
> >       NameList.Add(IBQuery1.FieldByName('FullName').AsString);
>         IBQuery1.Next;
>       end;
> >     IBQuer1.Close;
> >   finally
> >     NameList.Free;
> >   end;

--
Jeff Overcash (TeamB)   | Talk about failure
(Please do not email    | To fall is not to fail
 me directly unless     | Failure isn't about falling down
 asked.  Thank You)     | Failure is staying down (Marillion)

Re:Using TStringList and TIBQuery result set


I hate it when I do that<g>.

--
Bill
(TeamB cannot answer questions received via email)

Re:Using TStringList and TIBQuery result set


I do it all the time in real code and run it and then sit there, and sit there,
and sit there ... <g>.

Quote
"Bill Todd (TeamB)" wrote:

> I hate it when I do that<g>.

> --
> Bill
> (TeamB cannot answer questions received via email)

--
Jeff Overcash (TeamB)   | Talk about failure
(Please do not email    | To fall is not to fail
 me directly unless     | Failure isn't about falling down
 asked.  Thank You)     | Failure is staying down (Marillion)

Re:Using TStringList and TIBQuery result set


Quote
In article <3BC07DB4.571BA...@onramp.net>, overc...@onramp.net wrote...

Hi,

Quote
> Details Details <g>.

I make that mistake almost weekly, its amazing how fast half a gig of
memory gets used up <g>

Cheers

Re:Using TStringList and TIBQuery result set


Thank you very much for the answers!

"Jeff Overcash (TeamB)" <overc...@onramp.net> wrote in message
news:3BC07DB4.571BA04A@onramp.net...

Quote
> Details Details <g>.  Actually if this is all you will be doing, use an
IBSQL
> instead (still keeping Phil's correction and Bill's code).

> Phil Shrimpton wrote:

> > In article <3bc06066$1_1@dnews>, "Bill Todd \(TeamB\)"
> > <bill.nos...@dbginc.com> wrote...

> > > var
> > >   NameList:        TStringList;
> > > begin
> > >   IBQuery1.Open;
> > >   NameList := TStringList.Create;
> > >   try
> > >     while not IBQuery1.EOF do
> >        begin
> > >       NameList.Add(IBQuery1.FieldByName('FullName').AsString);
> >         IBQuery1.Next;
> >       end;
> > >     IBQuer1.Close;
> > >   finally
> > >     NameList.Free;
> > >   end;

> --
> Jeff Overcash (TeamB)   | Talk about failure
> (Please do not email    | To fall is not to fail
>  me directly unless     | Failure isn't about falling down
>  asked.  Thank You)     | Failure is staying down (Marillion)

Other Threads