2013/9/26 Sven Barth <pascaldra...@googlemail.com> > > After change to this code in Clone(), I got this error: >> >> >> tree.pas(66,60) Error: Incompatible type for arg no. 2: Got >> "TIntTree.TTree$LongInt", expected "TTree" >> > > Seems like a bug in 2.6.x. It's compiling in 2.7.1. >
I altered the code so that it works in 2.6.2: === test program === program test; {$mode objfpc}{$H+} uses tree; type TIntTree = class(specialize TTree<Integer>) public function Clone: TIntTree; end; function TIntTree.Clone: TIntTree; begin Result := TIntTree.Create(Data, FParent); DoClone(Result); end; var it1, it2 : TIntTree; begin it1 := TIntTree.Create(1, nil); it2 := it1.Clone; WriteLn(it1.ClassName); WriteLn(it2.ClassName); end. === tree clone code === type generic TTree<T> = class ... ... protected procedure DoClone(Target: TTree); public ... ... function Clone: TTree; ... ... end; implementation procedure TTree.DoClone(Target: TTree); var node: TTree; begin node := FirstChild; while node <> nil do begin node.Clone.Remove(Target); node := node.NextSibling; end; end; function TTree.Clone: TTree; begin Result := TTree.Create(Data, FParent); DoClone(Result); end; ======= Is there any problem with this solution? Regards, Xiangrong
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal