Board index » delphi » How do I get table info. at runtime please?

How do I get table info. at runtime please?

 Help with this would be much appreciated: I want to select from
 combobox any of the tables in my datamodule, and having done so
 view the field names in another combobox.

 I have achieved the second part but only by hard coding the table
 selection when in fact I want to pick the table at runtime.

 Many thanks.

 

Re:How do I get table info. at runtime please?


Quote
cm4...@mail.wlv.ac.uk (Pete Chapman) wrote:

>  Help with this would be much appreciated: I want to select from
>  combobox any of the tables in my datamodule, and having done so
>  view the field names in another combobox.

>  I have achieved the second part but only by hard coding the table
>  selection when in fact I want to pick the table at runtime.

I suppose the unit of that datamodule is already in the uses clause of
your form. The following routine, put in whatever appropriate
event-handler, will then extract TTable-references (or whatever you
would like) from that datamodule:

For Counter := 0 to DataModule2.ComponentCount-1 do
        if DataModule2.Components[Counter] is TTable
        then
        Listbox1.Items.Add((DataModule2.Components[Counter] as
TTable).TableName);

Good luck!

Jasper

PS: please take into consideration
- when replying, I just think I know;
- when asking, be sure that I don't.

Re:How do I get table info. at runtime please?


Quote
In article <31bff06c.17337...@news.euronet.nl> dirks...@euronet.nl (Jasper Stil) writes:
>From: dirks...@euronet.nl (Jasper Stil)
>Subject: Re: How do I get table info. at runtime please?
>Date: 13 Jun 1996 10:45:24 GMT
>cm4...@mail.wlv.ac.uk (Pete Chapman) wrote:

>>  Help with this would be much appreciated: I want to select from
>>  combobox any of the tables in my datamodule, and having done so
>>  view the field names in another combobox.

>>  I have achieved the second part but only by hard coding the table
>>  selection when in fact I want to pick the table at runtime.
>I suppose the unit of that datamodule is already in the uses clause of
>your form. The following routine, put in whatever appropriate
>event-handler, will then extract TTable-references (or whatever you
>would like) from that datamodule:
>For Counter := 0 to DataModule2.ComponentCount-1 do
>        if DataModule2.Components[Counter] is TTable
>        then
>        Listbox1.Items.Add((DataModule2.Components[Counter] as
>TTable).TableName);
>Good luck!
>Jasper

you could also look in the delphi 1 demos - i'm not sure if they're the same
for D2 - but look in a directory called demos\db\tools - there is a unit there
which contains 4 components :

 tdatabselist, ttablelist,tfieldlist & tindexlist

which are quite useful for getting table info. And they are authorative
borland & work well

HTH

boris

Re:How do I get table info. at runtime please?


Quote
Jasper Stil wrote:

> cm4...@mail.wlv.ac.uk (Pete Chapman) wrote:

> >  Help with this would be much appreciated: I want to select from
> >  combobox any of the tables in my datamodule, and having done so
> >  view the field names in another combobox.

> >  I have achieved the second part but only by hard coding the table
> >  selection when in fact I want to pick the table at runtime.

> I suppose the unit of that datamodule is already in the uses clause of
> your form. The following routine, put in whatever appropriate
> event-handler, will then extract TTable-references (or whatever you
> would like) from that datamodule:

> For Counter := 0 to DataModule2.ComponentCount-1 do
>         if DataModule2.Components[Counter] is TTable
>         then
>         Listbox1.Items.Add((DataModule2.Components[Counter] as
> TTable).TableName);
> Hello,

why not using 'Session.GetTableNames'? It works fine (for me).The
declaration is:

procedure GetTableNames(const DatabaseName, Pattern: string;
Extensions, SystemTables: Boolean; List: TStrings);

Try it in this way:

MyForm.Button1Click(Sender: TObject);
var
   aTableList : TStringList;

begin
        aTableList := TStringList.Create;
        Session.GetTableNames(myDatabase,'*.*',true,false;aTableList);
        {...}
        {work with the Tablelist}
        aTableList.Free;
end;

HTH

Thomas

Other Threads