Closed Thread
Results 1 to 6 of 6

Thread: From opening another form

  1. #1
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    From opening another form

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: From opening another form

    Form2 is probably a child of Form1.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Join Date
    Dec 2009
    Posts
    11
    Rep Power
    0

    Re: From opening another form

    You must rather use 'Hide;'

    If you close the main form of an app, the entrire app will close.
    Michael Rockett | Inniosoft | Dev:station

  5. #4
    Firebird_38 is offline Programmer
    Join Date
    Aug 2008
    Posts
    126
    Rep Power
    0

    Re: From opening another form

    Yes. Like so:
    Code:
    form1.SwapMe;
    begin
     Hide;
     Form2.Show;
    end;
    And this is not safe.
    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:
    Code:
    Form2.OnClose(Sender:TObject);
    begin
     Form1.Show;
    end;
    That only works if it's allowed, of course.
    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.

  6. #5
    Firebird_38 is offline Programmer
    Join Date
    Aug 2008
    Posts
    126
    Rep Power
    0

    Re: From opening another form

    Ps.

    Form1.Visible:=False;

    does the exact same as

    Form1.Hide;

  7. #6
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: From opening another form

    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

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help me in opening jar files..
    By raghu in forum Java Help
    Replies: 5
    Last Post: 07-05-2010, 07:45 AM
  2. Opening projects
    By --VIP-- in forum General Programming
    Replies: 4
    Last Post: 07-07-2009, 01:55 AM
  3. Opening another program
    By Brettpach in forum C and C++
    Replies: 3
    Last Post: 04-28-2008, 04:14 PM
  4. [Help] Opening a game
    By ScreWe in forum Visual Basic Programming
    Replies: 7
    Last Post: 01-01-2008, 01:08 AM
  5. Opening new windows?
    By littlefranciscan in forum HTML Programming
    Replies: 14
    Last Post: 01-31-2007, 04:29 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts