unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Unit2, csDictionary;
type
TForm1 =
class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
procedure AddItem(Node: TORPNode);
function ReadItem(ID: Cardinal): TORPNode;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Dict: TIntegerDictionary;
implementation
{$R *.dfm}
function TForm1.ReadItem(ID: Cardinal): TORPNode;
var
pter: Pointer;
begin
Dict.Find(ID, pter);
Result := TORPNode(pter^);
end;
procedure TForm1.AddItem(Node: TORPNode);
begin
Dict.Add(Node.ID, Pointer(Node));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
fNode: TORPNode;
begin
Button2.Enabled := false;
for i := 0
to 1000
do
begin
fNode := TORPNode.Create;
fNode.ID := i;
fNode.Trst := Random(300000);
AddItem(fNode);
end;
ShowMessage('
Liste erstellt.');
Button2.Enabled := true;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i: Integer;
fNode: TORPNode;
begin
i := Random(1000);
fNode := ReadItem(i);
if fNode <>
nil then
begin
Memo1.Lines.Add(IntToStr(fNode.ID));
Memo1.Lines.Add('
---------');
Memo1.Lines.Add(IntToStr(fNode.Trst));
Memo1.Lines.Add('
');
end
else
Memo1.Lines.Add('
Misslungen...');
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
FreeAndNil(dict);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
dict := TIntegerDictionary.Create;
Button2.Enabled := false;
end;
end.
unit Unit2;
interface
Type
TORPNode =
class(TObject)
ID : Cardinal;
Trst: Integer;
end;
implementation
end.