[fpc-pascal]Polymorphism of class field

Patrick O'Leary gtg086a at prism.gatech.edu
Thu Aug 30 21:31:31 CEST 2001

<snip lots of code and comment>
>You can't. You'll either have to typecast to the actual type, or provide
>abstract functions as SetDataFromReal() and SetDataFromString() in TStackElem
>which are implemented in the descendents, and which set the data, based on
>the actual type.

Ahh.  Yes, that works quite nicely.  Actually, what I'm going to do is 
similar, I'm just going to set up one SetData* function for each type in 
TStackElem as abstract, then implement just the appropriate function in 
each descendant type.  This keeps me from having multiple implementations 
of each SetData* function for each descendant.

>In TStackReal the SetDataFromString can do 2 things: Attempt to convert 
>the string
>to a real (which would be my choice), or raise an error saying that the 
>data type
>is not supported.

Yes, error handling...a good idea (and something I always seem to forget!)

>TStackCharString can do the opposite with SetDataFromReal.

Thank you for your very rapid response.

>fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org

Patrick O'Leary
patrick.oleary at resnet.gatech.edu

More information about the fpc-pascal mailing list