Hi,
I have one form that opens another form when a button is clicked. The thing is I want the original form to close when the new form opens. I tried doing something like on the click of the button form1.close. But it doesn't work, well it does, ie form1 closes, but then form2 opens and closes in a blink also!
I think that form2 is linked to form1 somehow? so when form1 is closed, it automatically closes. So for now, I have made form1.visible:=false whenever I click the button, but I'm just wondering if there is a way
Thanks
Form2 is probably a child of Form1.
You must rather use 'Hide;'
If you close the main form of an app, the entrire app will close.
Michael Rockett | Inniosoft | Dev:station
Yes. Like so:
And this is not safe.Code:form1.SwapMe; begin Hide; Form2.Show; end;
Now your main form is hidden. Guess what happens next?
Your user decides to close Form2. It disappears (it actually hides again)
Form1 is open, but hidden. Your app is running, but invisible. Where'd it go?
Use TaskManager to kill it outside of the IDE. You can't close it nicely with
the taskmanager. You'd have to send a WM_QUIT message (complicated stuff).
To fix this, you could write:
That only works if it's allowed, of course.Code:Form2.OnClose(Sender:TObject); begin Form1.Show; end;
Ps., create the handler from the object inspector, and I may have to params wrong.
Also, think of using TForm.OnCloseQuery to prevent forms from being closed.
Ps.
Form1.Visible:=False;
does the exact same as
Form1.Hide;
Yeh thats the thing!
I have now got a program that whenever I close any other forms apart from the main one, it doesnt actually close the app, coz Form1 is still open, but i cant close it.
Wlel, Ill try what you suggested on a later date and Ill reply back with results
Thanks
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks