#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    42
    Rep Power
    1

    CloseModal function not exiting form or Application


    I do have Exit menu at my application main menu tab as shown in screenshot, which upon click expected to exit an application or close application.



    My code is as follows

    Code:
    var
      FrmMain: TFrmMain;
    
    procedure TFrmMain.CloseClick(Sender: TObject);
    begin
         FrmMain.CloseModal;
    end;
    However when I clicked on Exit menu it is not quitting form/ application, It seems like CloseModal function is not working. How to make it work?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    42
    Rep Power
    1
    I have just noticed that

    FrmMain.Free; do work fine and exiting application.

    Wondering why CloseModal or Close do not work.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    42
    Rep Power
    1
    FrmMain.Free is not completely closing application there instances of Form still running at background.

    Because when I ran application again I got error

    [dcc32 Fatal Error] F2039 Could not create output file '.\Win32\Debug\JWCPro1.exe'

    Then I had shut down and restart PC again.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    353
    Rep Power
    7
    Originally Posted by ninadgac
    I do have Exit menu at my application main menu tab as shown in screenshot, which upon click expected to exit an application or close application.



    My code is as follows

    Code:
    var
      FrmMain: TFrmMain;
    
    procedure TFrmMain.CloseClick(Sender: TObject);
    begin
         FrmMain.CloseModal;
    end;
    However when I clicked on Exit menu it is not quitting form/ application, It seems like CloseModal function is not working. How to make it work?
    I'm assuming the form you are attempting to close is the main form of your application. Simple use "Close" to close the form and since it is the main form, it'll close the application, or if it isn't the main form, then you can use Application.Terminate instead.

    Also, Never use the Form Name "FrmMain" in your code. First, it just isn't necessary. Without the object reference included, it associated the code to the form instance, but if you insist on adding the object reference, then use "self" instead. SELF always refers to the Object listed in the procedure header declaration:

    procedure TFrmMain.CloseClick(Sender: TObject);

    Code:
    var
      FrmMain: TFrmMain;
    
    procedure TFrmMain.CloseClick(Sender: TObject);
    begin
        Close;
        //or
        //Application.Terminate;
        //or
        //Self.Close;
    end;

    Comments on this post

    • ninadgac agrees
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    42
    Rep Power
    1
    Your method worked out.

    Actually main problem was that I had put Menu name as Close so it was showing me Close as MenuItem variable not as a procedure/function. I renamed Menu Item with different name and Close worked fine.

IMN logo majestic logo threadwatch logo seochat tools logo