procedure TForm1.Button1Click(Sender: TObject);
begin
if not Assigned(Form2) then
begin
Form2:=TForm2.Create(Application);
Form2.ShowModal;
Form2.Free;
Form2:=Nil;
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
Form2.Caption:='TEST CHANGE CAPTION';
end;
也许这个可以:
procedure TForm2.button2click(Sender: TObject);
var
MyForm: TComponent;
begin
MyForm := Button2.Parent;
while not (MyForm is TForm) do
MyForm := MyForm.Parent;
MyForm.Caption := 'asdfasf';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Assigned(Form2) then
begin
Form2.Caption:='测试';
Form2.ShowModal;
end
else
begin
Form2:=TForm2.Create(Application);
Form2.Caption:='测试';
Form2.ShowModal;
end;
end;