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

Reply via email to