Board index » delphi » Interesting TypeCasting Problem

Interesting TypeCasting Problem

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

J   : Integer;

    for J := 0 to MyDataModule.MyTable.FieldCount - 1 do

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:

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

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


The above code fails at the TTable declaration.


David Sweeney
Texas A&M University


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)
 David Sweeney wrote in article <01bc8010$a18b6330$0acdc280@ats>...

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


Other Threads