<p>Am 23.09.2013 07:15 schrieb "Zaher Dirkey" <<a href="mailto:parmaja@gmail.com">parmaja@gmail.com</a>>:<br>
><br>
> Hi,<br>
> I have objects (classes) derived from base one<br>
><br>
> TBaseObject = class(TObject)<br>
> public<br>
> constructor Create; virtual;<br>
> function Clone:TBaseObject;<br>
> end;<br>
><br>
> TMyObject = class(TBaseObject)<br>
> my fields here<br>
> end;<br>
><br>
> o1, o2:TmyObject;<br>
> o1 already created;<br>
><br>
> o2 := o1.Clone;<br>
><br>
> in Clone i want to create new object from TmyObject but in base object in Clone method,like this<br>
><br>
> TBaseObject.Clone:TBaseObject;<br>
> begin<br>
> Result:=TBaseObject(ClassType).Create;//I know it is wrong here<br>
> end;<br>
><br>
> A<br>
> ny good idea?</p>
<p>You need to add a "Result.Assign(Self)" to your clone call and implement a virtually inherited "Assign" method in each class where you copy all fields. This is how "TPersistent" and its descendants do it as well.</p>
<p>Regards,<br>
Sven</p>