AFAIK, you must create a new type: type TMyGenericInt = specialize TMyGeneric<Integer>; var VMyGenericInt: TMyGenericInt;
begin VMyGenericInt:= TMyGenericInt.Create; VMyGenericInt.Value := 2014; VMyGenericInt.Free; end. 2014-10-31 2:14 GMT+07:00 silvioprog <silviop...@gmail.com>: > Hello, > > How to use this code below in mode objfpc?: > > TMyGeneric<T> = class(TObject) > private > FValue: T; > public > property Value: T read FValue write FValue; > end; > > ... > > var > VMyGenericStr: TMyGeneric<Integer>; > VMyGenericInt: TMyGeneric<string>; > begin > VMyGenericStr := TMyGeneric<Integer>.Create; > VMyGenericStr.Value := 2014; > VMyGenericStr.Free; > > VMyGenericInt := TMyGeneric<string>.Create; > VMyGenericInt.Value := 'Delphi Generics'; > VMyGenericInt.Free; > end; > > When I try: > > generic TMyGeneric<T> = class(TObject) > private > FValue: T; > public > property Value: T read FValue write FValue; > end; > > ... > > var > VMyGenericStr: specialize TMyGeneric<Integer>; > VMyGenericInt: specialize TMyGeneric<string>; > begin > VMyGenericStr := TMyGeneric<Integer>.Create; > VMyGenericStr.Value := 2014; > VMyGenericStr.Free; > > VMyGenericInt := TMyGeneric<string>.Create; > VMyGenericInt.Value := 'Delphi Generics'; > VMyGenericInt.Free; > end; > > I got: > > Error: Illegal expression > Error: Operator is not overloaded: "Class Of TMyGeneric$1" < "LongInt" > Fatal: Syntax error, ";" expected but "identifier CREATE" found > > Thank you! > > ps: FPC from trunk. > > -- > Silvio Clécio > My public projects - github.com/silvioprog > > _______________________________________________ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal >
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal