unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TSchueler=Array
of String;
TForm2 =
class(TForm)
FuellenMit10: TButton;
ListBox1: TListBox;
Umbenennen: TButton;
NachNameLoeschen: TButton;
procedure FuellenMit10Click(Sender: TObject);
procedure UmbenennenClick(Sender: TObject);
procedure NachNameLoeschenClick(Sender: TObject);
private
{ Private-Deklarationen }
FSchueler:TSchueler;
procedure DisplayArray;
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
Procedure AddSchueler(
var Arr:TSchueler;
const Entry:
String);
begin
SetLength(Arr, High(Arr) + 2);
Arr[High(Arr)] := Entry;
end;
Procedure RenameSchueler(
var Arr:TSchueler;
Index:Integer;
const NewEntryName:
String);
begin
if (
Index <= High(Arr))
and (
Index >= Low(Arr))
then Arr[
Index] := NewEntryName;
end;
Procedure DeleteByIndex(
var Arr:TSchueler;
Index:Integer);
var
i:Integer;
begin
if (
Index <= High(Arr))
and (
Index >= Low(Arr))
then
begin
if Index=High(Arr)
then SetLength(Arr,High(Arr))
else
begin
for I :=
Index + 1
to High(Arr)
do Arr[i - 1] := Arr[i];
SetLength(Arr,High(Arr));
end;
end;
end;
Procedure DeleteByName(
var Arr:TSchueler;
const EntryName:
String);
var
i:Integer;
foundIndex:Integer;
begin
foundIndex := -1;
i := Low(Arr) - 1;
while (i< High(Arr))
and (foundIndex = -1)
do
begin
inc(i);
if Arr[i] = EntryName
then foundIndex := i;
end;
if foundIndex > -1
then DeletebyIndex(Arr, FoundIndex);
end;
procedure TForm2.UmbenennenClick(Sender: TObject);
begin
RenameSchueler(FSchueler,5,'
Fünf');
DisplayArray;
end;
procedure TForm2.FuellenMit10Click(Sender: TObject);
var
i:Integer;
begin
for I := 1
to 10
do AddSchueler(FSchueler, '
Test ' +IntToStr(i));
DisplayArray;
end;
procedure TForm2.NachNameLoeschenClick(Sender: TObject);
begin
DeleteByName(FSchueler,'
Test 10');
DisplayArray;
end;
procedure TForm2.DisplayArray;
var
i:Integer;
begin
Listbox1.Items.Clear;
for I := Low(FSchueler)
to High(FSchueler)
do ListBox1.Items.Add(FSchueler[i]);
end;
end.