[fpc-pascal] constructor as procvar

Andrew Hall andrew.hall at shaw.ca
Sat Mar 20 18:56:56 CET 2010

Hi David,

If I'm reading your need correctly...

function CopyMyMammal(value: T_Mammal; extraParameters): T_Mammal;
  result := T_Mammal_Class(value.ClassType).Create(withExtraParameters);

Only confusion is you say you cannot make the type conversion? But the above code is correct and should compile...
If you cannot make it work, please post the code that will not compile and the error you are getting.

Regards,  Andrew.

On 20 Mar 10, at 10:26 , David Emerson wrote:

> How can I obtain a class type variable from an instance? I want to 
> create a second instance of the same descendant class (via the 
> constructor, which will take some parameters and make the new instance 
> unique)
> Tobject.classtype returns TClass (class of TObject) which I first 
> assumed would work great. However I cannot seem to do a type conversion 
> from TClass to t_mammal_class (class of t_mammal)! So I am stuck here.
> I tried just using TClass and skipping t_mammal_class, but then I can't 
> use my overriden constructor that takes special parameters.

More information about the fpc-pascal mailing list