<div dir="ltr">Hello,<div><br></div><div>How to use this code below in mode objfpc?:</div><div><br></div><div><div> TMyGeneric<T> = class(TObject)</div><div> private</div><div> FValue: T;</div><div> public</div><div> property Value: T read FValue write FValue;</div><div> end;</div><div><br></div><div>...</div><div><br></div><div><div>var</div><div> VMyGenericStr: TMyGeneric<Integer>;</div><div> VMyGenericInt: TMyGeneric<string>;</div><div>begin</div><div> VMyGenericStr := TMyGeneric<Integer>.Create;</div><div> VMyGenericStr.Value := 2014;</div><div> VMyGenericStr.Free;</div><div><br></div><div> VMyGenericInt := TMyGeneric<string>.Create;</div><div> VMyGenericInt.Value := 'Delphi Generics';</div><div> VMyGenericInt.Free;</div><div>end;</div></div><div><div><br></div><div>When I try:</div><div><br></div><div><div> generic TMyGeneric<T> = class(TObject)</div><div> private</div><div> FValue: T;</div><div> public</div><div> property Value: T read FValue write FValue;</div><div> end;</div></div><div><br></div><div>...</div><div><br></div><div><div>var</div><div> VMyGenericStr: specialize TMyGeneric<Integer>;</div><div> VMyGenericInt: specialize TMyGeneric<string>;</div><div>begin</div><div> VMyGenericStr := TMyGeneric<Integer>.Create;</div><div> VMyGenericStr.Value := 2014;</div><div> VMyGenericStr.Free;</div><div><br></div><div> VMyGenericInt := TMyGeneric<string>.Create;</div><div> VMyGenericInt.Value := 'Delphi Generics';</div><div> VMyGenericInt.Free;</div><div>end;</div></div><div><br></div><div>I got:</div><div><br></div><div><div>Error: Illegal expression<br></div><div>Error: Operator is not overloaded: "Class Of TMyGeneric$1" < "LongInt"</div><div>Fatal: Syntax error, ";" expected but "identifier CREATE" found</div></div><div><br></div><div>Thank you!</div><div><br></div><div>ps: FPC from trunk.</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></div></div>