On Fri, 23 Dec 2005 22:30:05 +0100
Florian Klaempfl <[EMAIL PROTECTED]> wrote:
> Micha Nelissen wrote:
> >
> > Comments are welcome.
>
> Make it a generic for use in a fpcontnr unit in fpc 2.1.x :)
VoilĂ :-). Maybe not in the way you imagined, but a nice test for generics
anyway :-). Seems that returning generic type does not work, and properties
do not work.
Micha
unit genlist;
{$mode objfpc}{$h+}
interface
uses
linkedlist;
type
TGenericLinkedList = generic(T) class(TLinkedList)
public
//error below function GetItem: T;
procedure SetItem(const NewItem: T);
public
constructor Create;
procedure Add(const AItem: T);
procedure Insert(const AItem: T);
function FindItem(const AItem: T): boolean;
//error: identifier not found T: property Item: T read GetItem write SetItem;
end;
implementation
constructor TGenericLinkedList.Create;
begin
inherited;
ItemSize := sizeof(T);
end;
(*
{ error: undefined identifier T }
function TGenericLinkedList.GetItem: T; inline;
begin
Result := T(inherited GetItemPointer^);
end;
*)
procedure TGenericLinkedList.SetItem(const NewItem: T); inline;
begin
Move(NewItem, inherited GetItemPointer^, sizeof(T));
end;
procedure TGenericLinkedList.Add(const AItem: T); inline;
begin
Last;
FEof := true;
Insert(AItem);
end;
procedure TGenericLinkedList.Insert(const AItem: T); inline;
begin
Move(AItem, inherited Insert^, sizeof(T));
end;
function TGenericLinkedList.FindItem(const AItem: T): boolean; inline;
begin
Result := inherited FindData(@AItem);
end;
end.
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel