[fpc-devel] Re: Illegal type conversion: "<enumeration type>"to "TObject"

Daniël Mantione daniel.mantione at freepascal.org
Fri Jul 18 18:33:43 CEST 2008



Op Fri, 18 Jul 2008, schreef Craig Peterson:

> ???? ??????????? wrote:
>> 1. Why not use dummy class like "class tmyenum(tobject) e: myenumtype; 
>> end;"?
>> (extra typing is something like "(objects[i] as tmyenum).e" instead of 
>> typecasting, but you can [have to] "Free" it: it's normal object)
>
> Why would that be better than a simple typecast?

Because you know it is compatible with a Tobject.

> Typecasting to/from an object is a fast and easy way to associate an 
> integer or enum with the strings in a TStrings object.

As you have experienced it might be fast, but not easy, since you are 
making assumptions on the size of enums, causing portability issues 
between compilers and also platforms.

> We know when we're doing this, and TStrings 
> never does anything with the object, so the alternatives add runtime and code 
> overhead that simply isn't needed.

True.

> Even if this was a one off thing I'd question introducing an object for 
> it, but in our case there's literally dozens of spots where we use the 
> technique with many different enumerated types.

It's hacking around library limitations. Library limitations should not be 
fixed with language changes, but by fixing the libraries.

Daniël


More information about the fpc-devel mailing list