[fpc-pascal] Clone a instance of object

Zaher Dirkey parmaja at gmail.com
Mon Sep 23 07:15:25 CEST 2013


Hi,
I have objects (classes) derived from base one

TBaseObject = class(TObject)
public
   constructor Create; virtual;
   function Clone:TBaseObject;
end;

TMyObject = class(TBaseObject)
   my fields here
end;

o1, o2:TmyObject;
o1  already created;

o2 := o1.Clone;

in Clone i want to create new object from TmyObject but in base object in
Clone method,like this

TBaseObject.Clone:TBaseObject;
begin
  Result:=TBaseObject(ClassType).Create;//I know it is wrong here
end;

A
​ny good idea?​

-- 
I am using last revision of Lazarus, FPC 2.6 on Windows XP SP3

Best Regards
Zaher Dirkey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130923/9c73971e/attachment.html>


More information about the fpc-pascal mailing list