Delphi-Quellcode:
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure MyEditKeyPress(Sender: TObject; var Key: Char);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
EditArray: array[0..4] of TEdit;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
for i := 0 to length(EditArray) - 1 do
begin
EditArray[i] := TEdit.Create(Form1);
EditArray[i].Parent := Form1;
EditArray[i].Name :='Edit'+IntToStr(i);
EditArray[i].Left := 10;
EditArray[i].Top := i*(EditArray[i].Height+10)+10;
EditArray[i].Text := EditArray[i].Name;
EditArray[i].OnKeyPress := MyEditKeyPress;
EditArray[i].Tag := i;
end;
end;
procedure TForm1.MyEditKeyPress(Sender: TObject; var Key: Char);
begin
if Sender is TEdit then
ShowMessage('Edit'+IntToStr((Sender as TEdit).Tag));
end;
Gleich mit der Mäöglichkeit zu entscheiden, welches Edit es ist.