Somebody correct me if I'm wrong here, but I think your problem is due to classes not having a virtual method structure in the way that instances do - the type cast mechanism returns a concrete class, and the class explicitly defines the constructor. So if the TGraphicClass constructor ever did anything other than what the TGraphicClass constructor does, then it would not be a TGraphicClass. You're getting what you directly ask for.

Terry


Jianming Lin (ASL) wrote:


Another example for clearifying my problem :

var CallNo : Integer;

Type TMyGraphic = class(TGraphic)
public
constructor Create; override;
procedure Assign(Source: TPersistent); override;
end;

procedure TMyGraphic.Assign(Source: TPersistent);
begin
//
end;

constructor TMyGraphic.Create;
begin
inherited;
CallNo := CallNo + 1;
end;


//------------------------------------------------------------------------
procedure TryIt;
var gCls : TGraphicClass;
nGra : TGraphic;
myPic : TPicture;
begin
CallNo := 0;
gCls := TGraphicClass(TMyGraphic);
nGra := gCls.Create;
ShowMessage(IntToStr(CallNo)); // 0 It Should be 1, but not,
Why ??????????

myPic := TPicture.Create;
myPic.Graphic := nGra;
ShowMessage(IntToStr(CallNo)); // 1
end;

#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal
For more information please visit www.marshalsoftware.com
#####################################################################################
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/



---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to