<div dir="ltr"><div><div><div><div><div><div><div><div><div>Hi All,<br><br></div>I have this generic class:<br><br><span style="font-family:courier new,monospace">type<br> generic TTree<T> = class<br> private<br> FItems: TList;<br>
... ...<br> public<br> Data: T;<br> ... ...<br> function FirstChild: TTree;<br> ... ...<br> end;<br><br>function TTree.FirstChild: TTree;<br>begin<br> if FItems.Count = 0 then Exit(nil);<br> Exit(TTree(FItems[0]));<br>
end;<br><br></span></div><span style="font-family:courier new,monospace">when using it, I did:<br><br></span></div><span style="font-family:courier new,monospace">type<br></span></div><span style="font-family:courier new,monospace"> TStringTree = specialize TTree<string>;<br>
<br></span></div><span style="font-family:courier new,monospace">It generated a compilation error:<br><br>Error: Incompatible types: got "TTree" expected "TTree$AnsiString"<br><br></span></div><span style="font-family:courier new,monospace">on the line "</span><span style="font-family:courier new,monospace">Exit(TTree(FItems[0]));" of function FirstChild.<br>
<br></span></div><span style="font-family:courier new,monospace">And I tried to change it to:<br><br></span><span style="font-family:courier new,monospace">Exit(TTree<T>(FItems[0]));<br><br></span></div><span style="font-family:courier new,monospace">But is not accepted.<br>
<br></span></div><span style="font-family:courier new,monospace">How to solve this? thanks.<br></span><div><div><div><div><div><span style="font-family:courier new,monospace"><br></span></div></div></div></div></div></div>