unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMList=^mlist;
mlist=record
pole:string[20];
prev,next:TMList;
end;
MyList=class
Private
FList:TMList;
FFirst:TMList;
FLast:TMList;
FCount:Integer;
function GetString(Index:Integer):string;
procedure SetString(Index:Integer; const s:string);
Public
Constructor Create;
property Count:Integer read FCount;
property First:TMList read FFirst;
property Last:TMList read FLast;
property Strings[Index: Integer]: string read GetString write SetString;
Destructor Destroy; Override;
function Add(const s:string):Integer;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
Constructor MyList.Create;
Begin
inherited;
FCount:=0;
FFirst:=nil;
FLast:=nil;
End;
Destructor MyList.Destroy;
var
temp:TMList;
Begin
inherited;
If FLast<>nil then
begin
While FLast^.prev<>nil do
begin
temp:=FLast;
FLast:=FLast^.prev;
Dispose(temp);
end;
Dispose(FLast);
end;
End;
function MyList.Add(const s:string):Integer;
var
temp:TMList;
begin
inc(FCount);
If FCount=1 then
begin
New(FFirst);
First^.pole:=s;
First^.prev:=nil;
First^.next:=nil;
FList:=FFirst;
FLast:=First;
end
else
begin
New(temp);
FLast^.next:=temp;
temp^.pole:=s;
temp^.prev:=FLast;
temp^.next:=nil;
FList:=temp;
FLast:=FList;
end;
Result:=FCount-1;
end;
function MyList.GetString(Index:Integer):string;
var
i:Integer;
temp:TMList;
begin
If (Index<0) or (Index>FCount-1) then
;//exception
temp:=FFirst;
For i:=0 to index-1 do
temp:=temp^.next;
FList:=temp;
Result:=temp^.pole;
end;
procedure MyList.SetString(Index:Integer; const s:string);
var
i:Integer;
temp:TMList;
begin
If (Index<0) or (Index>FCount-1) then
;//exception
temp:=FFirst;
For i:=0 to index-1 do
temp:=temp^.next;
FList:=temp;
temp^.pole:=s;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
d:MyList;
begin
d:=MyList.Create;
d.Add('www');
d.Add('bbb');
d.Add('ccc');
Edit1.Text:=d.Strings[1];
end;
end.