I’m having trouble closing a form( in the main form case) when I open a second form

Asked

Viewed 46 times

1

I’ve tried that already:

procedure TForm1.btnYesClick(Sender: TObject);
begin
Form4:=TForm4.Create(Application);
Form4.ShowModal;
Form1.Hide;
end;

And this tbm:

procedure TForm1.btnYesClick(Sender: TObject);
begin
Form4:=TForm4.Create(Application);
Form4.ShowModal;
Form1.Close;
end;

But nothing works, I’ve even tried to use a trial.

  • Form1.Close; already closes the form what the same problem, be more specific.

  • the problem is that it is not closing the way it had, it only creates the form 4 but does not close the Form1

2 answers

2


The Line after Showmodal only runs after you close Form4, so you are not running Hide or Close on Form1.

Replace with

Form4.Show;

and test again.

0

It doesn’t make much sense to close the Main Form while another one is open because the main closure closes the application. So, if I understand correctly, you want the main form to be invisible while the other one is displayed. This code should solve:

procedure TForm1.Button1Click(Sender: TObject); begin form2 := TForm2.Create(nil); Visible := False; try form2.ShowModal; finally form1.Visible := True; form2.Free; end; end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.