<div dir="ltr"><div>AFAIK, you must create a new type:<br><br></div>type<br> TMyGenericInt = specialize TMyGeneric<Integer>;<br>var<br> VMyGenericInt: TMyGenericInt;<br><br>begin<br> VMyGenericInt:= TMyGenericInt.Create;<br> VMyGenericInt.Value := 2014;<br> VMyGenericInt.Free;<br>end.<br></div><div class="gmail_extra"><br><div class="gmail_quote">2014-10-31 2:14 GMT+07:00 silvioprog <span dir="ltr"><<a href="mailto:silvioprog@gmail.com" target="_blank">silvioprog@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br><div>Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a></div>
</font></span></div></div></div>
<br>_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br></blockquote></div><br></div>