<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2013/9/29 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">
<br>
I would suggest you to add an additional protected virtual method to TTree<> which is called from TTree<>.Clone and you override that in your descendant classes.<br></blockquote><div><br>Could<div class="gmail_default" style="font-family:courier new,monospace;display:inline">
you please give an example how to do this? I tried the following:<br><br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">=== code start ===<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">
function TTree.DoClone: TTree; //protected, virtual<br>begin<br> Result := TSelfClass(Self.ClassType).Create(Data, FParent);<br>end;<br><br>function TTree.Clone: TTree;<br>var<br> node: TTree;<br>begin<br> Result := DoClone;<br>
node := FirstChild;<br> while node <> nil do begin<br> node.Clone.Remove(Result);<br> node := node.NextSibling;<br> end;<br>end;<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">
=== code end ===<br><br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">However, this does not work, because it seems that I cannot make any generic method virtual! In TIntTree, I have to write:<br>
<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">function TIntTree.DoClone: TIntTree;<br><br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">
As it is not possible to write TTree outside of the generic definition.<br><br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">Regards,<br>Xiangrong<br></div> </div></div></div></div>