Board index » delphi » List of available tables in a database

List of available tables in a database

I have a TTable in my application.  I want to choose in a ComboBox to change
of TableName in the same Database.

But how to list all available TableName of a Database ?

Pascal Vrancken

 

Re:List of available tables in a database


Use:

var
  S: TStrings;
begin
  S := TStringList.Create;
  try
    Table1.Database.Session.GetTableNames(S);
    ...
  finally
    S.Free;
  end;
end;

"Pascal Vrancken" <vranc...@bipt.be> schreef in bericht
news:8b5aq7$38l$1@naxos.belnet.be...

Quote
> I have a TTable in my application.  I want to choose in a ComboBox to
change
> of TableName in the same Database.

> But how to list all available TableName of a Database ?

> Pascal Vrancken

Re:List of available tables in a database


I have a problem with the solution.  If I have a TTABLE (Table1) and I want
to access the GetTableNames, I receive an error : 'Project ...
EAccessViolation with message Access violation at address ... in module
...'.

What's the cause of the problem in my following code :

var
  ts : tstrings;
begin
  ts := TStringList.Create;
  try

Table1.Database.Session.GetTableNames(Table1.DatabaseName,'*.db',false,false
,ts);
    ComboBoxTable.Items := ts;
  finally
    ts.Free;
  end;
  ...
end;

Quote
Steve Koterski <koter...@NOSPAMgte.net> wrote in message

news:38d64eeb.4991721@news.gte.net...
Quote
> On Mon, 20 Mar 2000 14:59:01 +0100, "Pascal Vrancken"
> <vranc...@bipt.be> wrote:

> >I have a TTable in my application.  I want to choose in a ComboBox to
change
> >of TableName in the same Database.

> >But how to list all available TableName of a Database ?

> See the TSession.GetTableNames method. This method populates the
> pre-existing string list object specified in the List argument with
> the names of the table specified in the DatabaseName argument.

>   Session.GetTableNames(Database1.DatabaseName, '*.*', False,
>     False, ComboBox1.Items);

> ///////////////////////////////////////////////////////////
> Steve Koterski              "No matter how cynical you get,
> Felton, CA                  it is impossible to keep up."
>                                              -- Lily Tomlin

Re:List of available tables in a database


I have a problem with the solution.  If I have a TTABLE (Table1) and I want
to access the GetTableNames, I receive an error : 'Project ...
EAccessViolation with message Access violation at address ... in module
...'.

What's the cause of the problem in my following code :

var
  ts : tstrings;
begin
  ts := TStringList.Create;
  try

Table1.Database.Session.GetTableNames(Table1.DatabaseName,'*.db',false,false
,ts);
    ComboBoxTable.Items := ts;
  finally
    ts.Free;
  end;
  ...
end;

Quote
M.H. Avegaart <avega...@NOSPAMmccomm.nl> wrote in message

news:8b5lb3$c9n$1@porthos.nl.uu.net...
Quote
> Use:

> var
>   S: TStrings;
> begin
>   S := TStringList.Create;
>   try
>     Table1.Database.Session.GetTableNames(S);
>     ...
>   finally
>     S.Free;
>   end;
> end;

> "Pascal Vrancken" <vranc...@bipt.be> schreef in bericht
> news:8b5aq7$38l$1@naxos.belnet.be...
> > I have a TTable in my application.  I want to choose in a ComboBox to
> change
> > of TableName in the same Database.

> > But how to list all available TableName of a Database ?

> > Pascal Vrancken

Re:List of available tables in a database


The session has to be open. So you should use:

Table1.DBSession.Active := True;
Table1.DBSession.GetTableNames(Table1.DatabaseName, '*.db', True, False,
ComboBoxTable.Items);

"Pascal Vrancken" <vranc...@bipt.be> schreef in bericht
news:8b7oao$mm3$1@naxos.belnet.be...

Quote
> I have a problem with the solution.  If I have a TTABLE (Table1) and I
want
> to access the GetTableNames, I receive an error : 'Project ...
> EAccessViolation with message Access violation at address ... in module
> ...'.

> What's the cause of the problem in my following code :

> var
>   ts : tstrings;
> begin
>   ts := TStringList.Create;
>   try

Table1.Database.Session.GetTableNames(Table1.DatabaseName,'*.db',false,false
Quote
> ,ts);
>     ComboBoxTable.Items := ts;
>   finally
>     ts.Free;
>   end;
>   ...
> end;

> M.H. Avegaart <avega...@NOSPAMmccomm.nl> wrote in message
> news:8b5lb3$c9n$1@porthos.nl.uu.net...
> > Use:

> > var
> >   S: TStrings;
> > begin
> >   S := TStringList.Create;
> >   try
> >     Table1.Database.Session.GetTableNames(S);
> >     ...
> >   finally
> >     S.Free;
> >   end;
> > end;

> > "Pascal Vrancken" <vranc...@bipt.be> schreef in bericht
> > news:8b5aq7$38l$1@naxos.belnet.be...
> > > I have a TTable in my application.  I want to choose in a ComboBox to
> > change
> > > of TableName in the same Database.

> > > But how to list all available TableName of a Database ?

> > > Pascal Vrancken

Other Threads