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

Пётр Косаревский ppkk at mail.ru
Fri Jul 18 18:57:21 CEST 2008


> > 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?  Typecasting to/from an 
> object is a fast and easy way to associate an integer or enum with the 
> strings in a TStrings object.  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.  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.
> Craig
 
Well, at first it's better because we wouldn't discuss it.

I used it because I was not sure, whether TObject nature may matter or not in Delphi and FPC I used (I could study source code, but what about future versions?) and it was faster to program, than to ponder over.

When needed, it was easy to add fields to class etc. I even managed to benefit from polymorphism once or twice: it was easier than rewriting all functions for the heavier list.

However, with objects FPC program used more memory (than Delphi) and both used more memory than ones with typecasting, and I had to free objects (one cycle). And I have chosen objects the first time because I thought of typecasting as of bad practice.



More information about the fpc-devel mailing list