Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-01

generics with is operator

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

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

Reply by email