#1
  1. Huh?
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Scotland, UK
    Posts
    223
    Rep Power
    12

    creating and deleting a form using BCB


    Hey!

    I have a program that creates a child form when a button on the main form is pressed. This is done using Borland C++ Builder. The code doing this is:

    [CODE]

    SearchWindow = new TForm2( this );
    SearchWindow -> Show();
    [\CODE]

    However, when i close this form (SearchWindow) by clicking the 'x' in the corner of box i need to delete the form but i cannot get this to work. Any ideas on what i need to do?

    I have tried putting the code:

    delete SearchWindow

    in both the onClose event handler for the child handler and also in the MainForm but i cannot get it to work properly. I need to know where to put this code and if that is the correct syntax for it.

    All help is appreciated!

    TIA :-)
    -----------------------------------------------------------
    4dr14n
  2. #2
  3. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Location
    Fly-over country
    Posts
    1,172
    Rep Power
    30
    In the OnClose event handler put the following line of code:

    Action = caFree;
  4. #3
  5. Huh?
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Scotland, UK
    Posts
    223
    Rep Power
    12
    Thanx for the reply! :)

    That code works if i close the form using the x in the corner of the box but what if i have a button on the form to close it?

    if i type in the code for the button action as:

    form = Close();

    i get an error about an invalid address.

    what should i do in this case?:confused:

    Thanx for helping!
    -----------------------------------------------------------
    4dr14n
  6. #4
  7. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Location
    Fly-over country
    Posts
    1,172
    Rep Power
    30
    I believe you need to try something like:

    form->Close();

    I'm not sitting at a machine I can verify this at so let me know if I'm wrong....
  8. #5
  9. Huh?
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Scotland, UK
    Posts
    223
    Rep Power
    12
    oops...my mistake! :eek:

    i AM typing
    form -> Close();

    NOT

    form = Close();

    as i originally typed. Sorry!!
    :D
    -----------------------------------------------------------
    4dr14n
  10. #6
  11. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Location
    Fly-over country
    Posts
    1,172
    Rep Power
    30
    Try:

    this->Close();

    or:

    Close();
  12. #7
  13. Huh?
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Scotland, UK
    Posts
    223
    Rep Power
    12
    Hey!

    Thanx for the help...very useful and much appreciated!

    Using

    Close();

    works fine. Thanks for your time. :)
    -----------------------------------------------------------
    4dr14n

IMN logo majestic logo threadwatch logo seochat tools logo