Board index » delphi » Delphi Class constructors using TClass references

Delphi Class constructors using TClass references

I want to create an object of a type specified by a TClass reference, like
this:

procedure CreateObject;
var
  ObjectRef : TObject;
  ClassRef  : TClass;
begin
  ClassRef:=TMyTypeOfObject;
  ObjectRef:=ClassRef.Create;
end;

Problem I am having is the class constructor is not being executed. The object
reference contains the RTTI I am expecting, that is, ClassType is
TMyTypeOfObject but object is 'empty'. What is going on? Anyone know?

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

 

Re:Delphi Class constructors using TClass references


Dave,

It's quite possible that in your class TMyTypeOfObject that you are not
overriding a virtual constructor in the ascendant class.
Hope this helps,

James

In article <6tjieh$86...@nnrp1.dejanews.com>,

Quote
  davebec...@my-dejanews.com wrote:
> I want to create an object of a type specified by a TClass reference, like
> this:

> procedure CreateObject;
> var
>   ObjectRef : TObject;
>   ClassRef  : TClass;
> begin
>   ClassRef:=TMyTypeOfObject;
>   ObjectRef:=ClassRef.Create;
> end;

> Problem I am having is the class constructor is not being executed. The object
> reference contains the RTTI I am expecting, that is, ClassType is
> TMyTypeOfObject but object is 'empty'. What is going on? Anyone know?

> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Other Threads