* make tgeneric10 more complex

git-svn-id: trunk@5359 -
This commit is contained in:
micha 2006-11-13 20:13:02 +00:00
parent 056ee3c865
commit 90b19e0be2
4 changed files with 38 additions and 23 deletions

1
.gitattributes vendored
View File

@ -6600,6 +6600,7 @@ tests/test/tvarset1.pp svneol=native#text/plain
tests/test/twide1.pp svneol=native#text/plain
tests/test/twide2.pp svneol=native#text/plain
tests/test/uabstrcl.pp svneol=native#text/plain
tests/test/ugeneric10.pp svneol=native#text/plain
tests/test/ugeneric3.pp svneol=native#text/plain
tests/test/ugeneric4.pp svneol=native#text/plain
tests/test/uimpluni1.pp svneol=native#text/plain

View File

@ -1,37 +1,23 @@
{$mode objfpc}
type
generic TList<_T>=class(TObject)
type public
TCompareFunc = function(const Item1, Item2: _T): Integer;
var public
data : _T;
compare : TCompareFunc;
procedure Add(item: _T);
end;
uses
ugeneric10;
procedure TList.Add(item: _T);
begin
data:=item;
if compare(data, 20) <= 0 then
halt(1);
end;
type
TMyIntList = specialize TList<integer>;
function CompareInt(Item1, Item2: Integer): Integer;
begin
Result := Item2 - Item1;
end;
type
TMyIntList = specialize TList<integer>;
var
ilist : TMyIntList;
someInt : integer;
begin
someInt:=10;
ilist := TMyIntList.Create;
ilist.compare := ilist.TCompareFunc(@CompareInt);
ilist.add(someInt);
ilist.sort(ilist.TCompareFunc(@CompareInt));
writeln('ok');
end.

View File

@ -2,12 +2,10 @@
type
generic TList<_T>=class(TObject)
type protected
TSelf = specialize TList<_T>;
var public
data : _T;
procedure Add(item: _T);
procedure Assign(Source: TSelf);
procedure Assign(Source: TList);
end;
procedure TList.Add(item: _T);
@ -15,7 +13,7 @@ begin
data:=item;
end;
procedure TList.Assign(Source: TSelf);
procedure TList.Assign(Source: TList);
begin
data:=Source.data;
end;

30
tests/test/ugeneric10.pp Normal file
View File

@ -0,0 +1,30 @@
unit ugeneric10;
{$mode objfpc}
interface
type
generic TList<_T>=class(TObject)
type public
TCompareFunc = function(const Item1, Item2: _T): Integer;
var public
data : _T;
procedure Add(item: _T);
procedure Sort(compare: TCompareFunc);
end;
implementation
procedure TList.Add(item: _T);
begin
data:=item;
end;
procedure TList.Sort(compare: TCompareFunc);
begin
if compare(data, 20) <= 0 then
halt(1);
end;
end.