[fpc-devel] generics with is operator

darekm at emadar.com darekm at emadar.com
Sun Jan 24 23:41:09 CET 2010


Hi

I found problem with is operator using with generics
This program is not compile
error is: Class or Object types "TList$LongInt" and "TList$ShortString"
are not related
But I think it should be possible


{$mode objfpc}

type
   generic TList<_T>=class(TObject)
   public
     data : _T;
     procedure Add(item: _T);
   end;

procedure TList.Add(item: _T);
begin
  data:=item;
end;


type
  TMyIntList = specialize TList<integer>;
  TMyStringList = specialize TList<string>;




var
  ilist : TMyIntList;
  slist : TMyStringList;
begin
  ilist := TMyIntList.Create;
  slist := TMyStringList.Create;
  if sList is tObject then writeln('slist object') else halt(1);
  if iList is tObject then writeln('ilist is  tobject') else halt(2);
  if ilist is tMyStringList then halt(3) else writeln('iList is no
tMyStringList ');

end.



Darek




More information about the fpc-devel mailing list