On 24/11/2011 19:34, Jonas Maebe wrote:
In that case, you did not hit the same problem as the original poster (your "I also 
hit this problem recently" is what triggered my response). His problem was that if 
you call a non-virtual constructor on a class reference variable, that the constructor is 
determined based on the static type of the class reference rather than on the dynamic 
type.

It does not matter much but i hit the same problem. Just replace class of TObj by class of TObject (TClass)

I stored a class (TMyClass) in a class variable (AClass: TClass). I was expecting that calling AClass.Create would call TMyClass.Create. Just like him i found that is not the case.

To be clear: i'm not saying that is a bug or asking for changing the behavior

The task is accomplished by other means

See 
http://code.google.com/p/emballo/source/browse/trunk/Src/Emballo.DI.Instantiator.pas#152
That's indeed a completely different technique to dynamically instantiate 
classes (and if you don't really need that kind of flexibility, I would 
recommend virtual constructors instead since they're much simpler and faster).

I will do in a third way, that keeps flexibility (and is also fast) but requires more typing.

Luiz
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to