<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2013/9/28 Sven Barth <span dir="ltr"><<a href="mailto:pascaldragon@googlemail.com" target="_blank">pascaldragon@googlemail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On second sight your solution is not correct, because you are using Clone inside your parent class which would not use the (non-virtual) Clone you created.<br>
<br>
I've now played around with 2.6.2 myself and this should solve this problem:<div class="im">
<br>
=== code begin ===<br>
<br>
type<br></div>
generic TTree<T> = class<br>
private type<br>
TSelfType = TTree;<br>
TSelfClass = class of TSelfType; // earlier I suggested TTree which 2.6.2 does not support=== code end ===<br><br></blockquote><div><br><div class="gmail_default" style="font-family:courier new,monospace;display:inline">
I think this solution only fixed the problem with 2.6.2 that you have to use TSelfType, but the logic is still not correct.<br><br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">
Using your modified version, I try to achieve some complex Clone</div> <div class="gmail_default" style="font-family:courier new,monospace;display:inline">strategy, for example, either one of the following:<br><br></div>
<div class="gmail_default" style="font-family:courier new,monospace;display:inline">1) the descendant has added a field other than Data that needs to be cloned;<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">
2) the clone is "non-verbatim", it will multiple Data by 2 when cloning.<br><br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">Let's use the 2nd one as an example, the following does not work:<br>
<br>type<br> TIntTree = class(specialize TTree<Integer>)<br> public<br> function Clone: TIntTree;<br> end;<br><br>function TIntTree.Clone: TIntTree;<br>begin<br> Result := TIntTree(inherited Clone);<br> Result.Data *= 2;<br>
end;<br><br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">It only multiple the ROOT node of the cloned tree, not every node. <br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">
<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">Regards,<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">Xiangrong<br></div></div>
</div></div></div>