On 23/09/13 10:02, Michael Van Canneyt wrote:
This is wrong. You are typecasting a class reference to an object instance.The following works: {$mode objfpc} Type TBaseObject = class(TObject) public constructor Create; virtual; function Clone:TBaseObject; end; TBaseObjectClass = Class of TBaseObject; constructor TBaseObject.Create; begin end; Function TBaseObject.Clone:TBaseObject; Var C : TBaseObjectClass; begin C:=TBaseObjectClass(ClassType); Result:=C.Create; end;
What would happen if Result := Self.ClassType.Create were used instead?
Type TMyObject = class(TBaseObject) // my fields here end; Var o1, o2:TmyObject; begin o1:=TMyObject.Create; o2 := o1.Clone as TmyObject; end.
Stephano _______________________________________________ fpc-pascal maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
