Autor Beitrag
Krischa
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 118

Windows 7 64 Bit
Delphi 2007
BeitragVerfasst: Mo 15.06.09 09:37 
Hi,
ich rufe in meiner Hauptform eine zweite auf und würde gerne wissen ob und wie ich der 2ten Form Variablen mit übergeben kann. Form2 rufe ich so auf:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
begin
  form2:=TForm2.Create(nil);
  try
    form2.ShowModal;
    if form2.ModalResult=mrOK then
    begin
      ....
    end
  finally
    form2.Free;    
end;


Danke im Vorraus.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 15.06.09 09:52 
Die Frage kam gerade erst. Hier findest du von mir ein Beispiel inkl. Beispielprojekt:
www.delphi-forum.de/....php?p=567110#567110

Das sähe bei dir also dann so aus:
ausblenden Unit1.pas
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
  Form2 := TForm2.Create(nil);
  try
    Form2.XYZ := 'Test';
    if Form2.ShowModal = mrOK then
    begin
      ....
    end
  finally
    Form2.Free;    
  end;
ausblenden Unit2.pas
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
type
  TForm2 = class(TForm)
  ...
  public
    XYZ: String;
  end;

...

procedure TForm2.Button1Click(Sender: TObject);
begin
  ShowMessage(XYZ);
end;
Nach dem ShowModal kannst du die natürlich auch wieder auslesen, wenn die Werte in Form2 verändert werden.
Krischa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 118

Windows 7 64 Bit
Delphi 2007
BeitragVerfasst: Mo 15.06.09 09:54 
Danke für die schnelle Hilfe :D