unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
PString = ^
String;
// Deklaration eines Zeiger auf einen String wg der Übersicht
TForm1 =
class(TForm)
Button1: TButton;
ListBox1: TListBox;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
procedure ClearStrings;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
iCnt : Integer;
aStr : PString;
begin
ClearStrings;
ListBox1.Clear;
For iCnt:=0
to 9
do
begin
New(aStr);
aStr^:='
TestString '+IntToStr(iCnt+1);
ListBox1.Items.AddObject('
TestString '+IntToStr(iCnt+1),TObject(aStr));
end;
// For iCnt:=0 to 9 do
end;
procedure TForm1.ClearStrings;
var
iCnt : Integer;
begin
For iCnt:=0
to ListBox1.Items.Count-1
do
If Assigned(ListBox1.Items.Objects[iCnt])
then
Dispose(PString(ListBox1.Items.Objects[iCnt]));
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
Label1.Caption:=PString(ListBox1.Items.Objects[ListBox1.ItemIndex])^ ;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ClearStrings;
end;
end.