<div dir="ltr"><div>Hello,</div><div><br></div><div>I tried this example (Lazarus 1.3 r46702 FPC 2.7.1 x86_64-linux-gtk 2; FPC from trunk too):</div><div><br></div><div><a href="http://blogs.teamb.com/craigstuntz/2008/08/29/37832">http://blogs.teamb.com/craigstuntz/2008/08/29/37832</a><br></div><div><br></div><div>and got the error:</div><div><br></div><div><div>Compile Project, Target: project1: Exit code 256, Errors: 3</div><div>unit1.pas(27,22) Error: Identifier not found "T"</div><div>unit1.pas(27,23) Error: Type identifier expected</div><div>unit1.pas(27,24) Error: Class or interface type expected, but got "<erroneous type>"</div></div><div><br></div><div>The code:</div><div><br></div><div><div>unit Unit1;</div><div><br></div><div>//{$mode objfpc}{$H+}</div><div>{$mode delphi}</div><div><br></div><div>interface</div><div><br></div><div>uses</div><div> Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;</div><div><br></div><div>type</div><div> TAdder<T> = class</div><div> public</div><div> function AddEm(A, B: T): T; virtual; abstract;</div><div> end;</div><div><br></div><div> TIntAdder = class(TAdder<integer>)</div><div> public</div><div> function AddEm(A, B: integer): integer; override;</div><div> end;</div><div><br></div><div> TStringAdder = class(TAdder<string>)</div><div> public</div><div> function AddEm(A, B: string): string; override;</div><div> end;</div><div><br></div><div> TMath<T; A: TAdder<T>, constructor> = class</div><div> public</div><div> function AddTwoDigits(Left, Right: T): T;</div><div> end;</div><div><br></div><div> { TForm1 }</div><div><br></div><div> TForm1 = class(TForm)</div><div> procedure Button1Click(Sender: TObject);</div><div> end;</div><div><br></div><div>var</div><div> Form1: TForm1;</div><div><br></div><div>implementation</div><div><br></div><div>{$R *.lfm}</div><div><br></div><div>{ TForm1 }</div><div><br></div><div>procedure TForm1.Button1Click(Sender: TObject);</div><div>var</div><div> AddInt: TMath<integer, TIntAdder>;</div><div> AddString: TMath<string, TStringAdder>;</div><div>begin</div><div> AddInt := TMath<integer, TIntAdder>.Create;</div><div> try</div><div> ShowMessage(IntToStr(AddInt.AddTwoDigits(2, 2)));</div><div> finally</div><div> AddInt.Free;</div><div> end;</div><div> AddString := TMath<string, TStringAdder>.Create;</div><div> try</div><div> ShowMessage(AddString.AddTwoDigits('2', '2'));</div><div> finally</div><div> AddString.Free;</div><div> end;</div><div>end;</div><div><br></div><div>{ TIntAdder }</div><div><br></div><div>function TIntAdder.AddEm(A, B: integer): integer;</div><div>begin</div><div> Result := A + B;</div><div>end;</div><div><br></div><div>{ TStringAdder }</div><div><br></div><div>function TStringAdder.AddEm(A, B: string): string;</div><div>begin</div><div> Result := IntToStr(StrToInt(A) + StrToInt(B));</div><div>end;</div><div><br></div><div>{ TMath<T, A> }</div><div><br></div><div>function TMath<T, A>.AddTwoDigits(Left, Right: T): T;</div><div>var</div><div> Add: A;</div><div>begin</div><div> Add := A.Create;</div><div> try</div><div> Result := Add.AddEm(Left, Right);</div><div> finally</div><div> Add.Free;</div><div> end;</div><div>end;</div><div><br></div><div>end.</div></div><div><br></div>--<br><div class="gmail_signature">Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a></div>
</div>