Einzelnen Beitrag anzeigen

Popov
(Gast)

n/a Beiträge
 
#6

AW: Zugriff auf Formular währen OnShow

  Alt 24. Apr 2015, 21:05
Nochmal mit Quellcode:

Projektdatei
Delphi-Quellcode:
program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas{Form1},
  Unit2 in 'Unit2.pas{Form2};

{$R *.res}

begin
  Form2 := TForm2.Create(Application); //rein

  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  //Application.CreateForm(TForm2, Form2); //raus
  Application.Run;
end.
Unit1/Form1 (Zugriff auf eine Komponente in Form2 bereits in Create von Form1)
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
  ShowMessage(Form2.Edit1.Text);
end;
Oder, wie himitsu meinte:
Projektdatei
Delphi-Quellcode:
program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas{Form1},
  Unit2 in 'Unit2.pas{Form2};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  //Application.CreateForm(TForm2, Form2); //raus
  Application.Run;
end.
Unit1/Form1
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
  Form2 := TForm2.Create(Application);
  ShowMessage(Form2.Edit1.Text);
  //Form2.Free; //wenn man es nicht mehr braucht
end;
  Mit Zitat antworten Zitat