fpc/tests/test/tgeneric11.pp
paul 790f6b0a4b compiler: use delphi syntax for type, const and var section declarations in classes instead of fpc generics syntax
rtl: fix fgl to use the new syntax
tests: fix generics tests to use the new syntax

git-svn-id: trunk@15646 -
2010-07-27 00:59:32 +00:00

46 lines
850 B
ObjectPascal

{$mode objfpc}
type
generic TList<_T>=class(TObject)
public
var
data : _T;
procedure Add(item: _T);
procedure Assign(Source: specialize TList<_T>);
end;
procedure TList.Add(item: _T);
begin
data:=item;
end;
procedure TList.Assign(Source: specialize TList<_T>);
begin
data:=Source.data;
end;
type
TMyIntList = specialize TList<integer>;
TMyStringList = specialize TList<string>;
var
ilist1, ilist2 : TMyIntList;
slist1, slist2 : TMyStringList;
begin
ilist1 := TMyIntList.Create;
ilist1.add(10);
ilist2 := TMyIntList.Create;
ilist2.add(20);
ilist2.assign(ilist1);
if ilist2.data <> 10 then
halt(1);
slist1 := TMyStringList.Create;
slist1.add('test');
slist2 := TMyStringList.Create;
slist2.add('hello');
slist2.assign(slist1);
if slist2.data <> 'test' then
halt(1);
end.