Board index » delphi » Gettin a variable type at runtime

Gettin a variable type at runtime

    Hi all,

    let's say I have a record defined in my program. Is there anyway to find
out what fields it has and what kind they are at runtime???

    Thanks,

    Alphonsus.

 

Re:Gettin a variable type at runtime


Hi Alphonsus,

as far as I know Delphi's RTTI (unit TypInfo) can't enumerate the members of
a record.
But - if appropriate - you could use classes instead of records and "look"
inside them with the TypInfo-functions.

Ruediger

Re:Gettin a variable type at runtime


Not with records. Define your Record as a Class instead, and publish the
properties that you want to inspect later.

--
http://www.techvette.com - Delphi and Corvette sources

Quote
"Alphonsus" <no_spam@no_spam> wrote in message news:3a93b79e_2@dnews...
>     Hi all,

>     let's say I have a record defined in my program. Is there anyway to
find
> out what fields it has and what kind they are at runtime???

>     Thanks,

>     Alphonsus.

Re:Gettin a variable type at runtime


Actually, there is.
RTL finalizes record variables too (string and interface members), so this
info is available, though I don't know if for all members or only those that
need finalization. This is nowhere documented, so unsafe to use.

So, better and safer is to use classes instead of records for this purpose.

--
Robert

Quote
David Lively wrote in message <3a93f7a2$1_1@dnews>...
>Not with records. Define your Record as a Class instead, and publish the
>properties that you want to inspect later.

>--
>http://www.techvette.com - Delphi and Corvette sources

>"Alphonsus" <no_spam@no_spam> wrote in message news:3a93b79e_2@dnews...
>>     Hi all,

>>     let's say I have a record defined in my program. Is there anyway to
>find
>> out what fields it has and what kind they are at runtime???

>>     Thanks,

>>     Alphonsus.

Other Threads