Board index » delphi » Interesting TypeCasting Problem

Interesting TypeCasting Problem

How can you typecast a string from a stringlist as a table?
This code works:

var
J   : Integer;

begin
    for J := 0 to MyDataModule.MyTable.FieldCount - 1 do
      ComboBox.Items.Add(MyDataModule.MyTable.Fields[J].DisplayLabel;

However, if you need to iterate this procedure for more than one table, the
obvous thing to do is to store the necessary tablenames in a TStringList.
This code does NOT work:

var
  I,J  : Integer;
RequestedTables : TStringList; {Requested tables is a list which holds two
table names
                                                 MyTable and MyTable2}

begin  
  for I := 0 to RequestedTables.Count - 1 do
    for J := 0 to dmCM.RequestedTables[I].AsString.FieldCount - 1 do

ComboBox.Items.Add(MyDataModule.TTable(RequestedTables[I].AsString).Fields[J
].DisplayLabel);

The above code fails at the TTable declaration.

Help!

David Sweeney
Texas A&M University
adapti...@tamu.edu

 

Re:Interesting TypeCasting Problem


Of course not.  You cannot typecast a string into an object, it just won't
work.  Instead of using a TStringList to store the names of the tables, use
a TList and store the table itself.
--
David S. Becker
ADP Dealer Services (Plaza R&D)
d...@plaza.ds.adp.com
(503)402-3236
 David Sweeney wrote in article <01bc8010$a18b6330$0acdc280@ats>...

Quote
>How can you typecast a string from a stringlist as a table?
>This code works:

[snip]

Other Threads