<div dir="ltr"><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">
<br>
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>
</blockquote><div><br><div class="gmail_default" style="font-family:courier new,monospace;display:inline">What If I make Clone virtual? If by adding "virtual" to Clone, the problem is solved, then what's the difference between virtual Clone and the method you provided?<br>
</div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
=== 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</blockquote><div><br><div class="gmail_default" style="font-family:courier new,monospace;display:inline">This compiles, however, if I remove my version of TIntTree (i.e. implement a Clone in it and call parent's DoClone), then the main program does not compile, it says:<br>
<br>demo2.lpr(20,13) Error: Incompatible types: got "TIntTree.TTree$LongInt" expected "TIntTree"<br><br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">I then can either:<br>
<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">1) add a Clone method to TIntTree and do a typecast inside it, as you said.<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">
2) do a typecast in the main program, i.e. it2 := it1.Clone as TIntTree.<br><br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">So, I guess the problem is solved? I have two further questions:<br>
<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">1) Why class of TTree does not work in 2.6.2 but class of TSelfType worked? Is it a problem of generics in 2.6.2, or it is *not* related to generics? I feel that TSelfType is same as TTree? <br>
</div><div class="gmail_default" style="font-family:courier new,monospace;display:inline"><br>2) What is the difference between the following:<br>
<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">- it2 := TIntTree(it1.Clone);<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">- it2 := it1.Clone as TIntTree;<br>
<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline">Where in the official document can I find the behavior/definition of "as"?<br><br>Thanks a lot.<br><br>Regards,<br></div>
<div class="gmail_default" style="font-family:courier new,monospace;display:inline">Xiangrong<br></div><div class="gmail_default" style="font-family:courier new,monospace;display:inline"><br></div></div></div><div class="gmail_extra">
<br></div></div>