mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-14 15:09:14 +02:00
+ testing procvartype in generic class
git-svn-id: trunk@5332 -
This commit is contained in:
parent
4bfe0e6819
commit
0ba8e25c8e
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -6448,6 +6448,7 @@ tests/test/tfpu4.pp svneol=native#text/plain
|
||||
tests/test/tfpu5.pp svneol=native#text/plain
|
||||
tests/test/tfpuover.pp svneol=native#text/plain
|
||||
tests/test/tgeneric1.pp svneol=native#text/plain
|
||||
tests/test/tgeneric10.pp svneol=native#text/plain
|
||||
tests/test/tgeneric2.pp svneol=native#text/plain
|
||||
tests/test/tgeneric3.pp svneol=native#text/plain
|
||||
tests/test/tgeneric4.pp svneol=native#text/plain
|
||||
|
36
tests/test/tgeneric10.pp
Normal file
36
tests/test/tgeneric10.pp
Normal file
@ -0,0 +1,36 @@
|
||||
{$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;
|
||||
|
||||
procedure TList.Add(item: _T);
|
||||
begin
|
||||
data:=item;
|
||||
if compare(data, 20) <= 0 then
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
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);
|
||||
end.
|
Loading…
Reference in New Issue
Block a user