Mach es mit einer Klassen-Methode. (Ist auch der bessere Stil, finde ich.)
Hauptformular:
Delphi-Quellcode:
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
Unit2;
procedure TForm1.Button1Click(Sender: TObject);
var
sl: TStringList;
begin
sl := TStringList.Create;
try
if TForm2.GetUserInput(sl) then
Listbox1.Items.Text := sl.Text;
finally
FreeAndNil(sl);
end;
end;
Eingabeformular:
Delphi-Quellcode:
type
TForm2 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
class function GetUserInput(out sl: TStringList): Boolean;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
class function TForm2.GetUserInput(out sl: TStringList): Boolean;
begin
with TForm2.Create(nil) do
begin
ShowModal();
sl.Add(Edit1.Text);
Result := length(Edit1.Text) <> 0;
Free();
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
ModalResult := mrOK;
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
ModalResult := mrCancel;
end;
Klappt wunderbar.