Is it possible to cast with the content of a variable?
Posted on 2004-03-22
This is just a question for knowledge, i was wondering( i checked a bit and found nothing on this ) if it's possible in delphi to cast with the content of a variable.
Like i could have a structure like this
case MyShape of
Circle : result := TCircle(MyShape).surface;
Square : result := TSquare(MyShape).surface;
Instead i would want
MyObjectType : string // or any other var type
Result := MyObjectType(MyShape).surface);
This is just a dummy exemple to show what i would like to do, in my program i get to a point that i need to cast my object type. but since i have many object possible my case get really huge and i was thinking that if it was possible to cast like this i could save a lots of lines.
Since i know this is not likely possible to do, points will go to the best explanation of why i can't.