Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close() gives an error message and doesn't close the application 1

Status
Not open for further replies.

Alex314

Programmer
May 22, 2008
6
0
0
NL
My skills as a programmer are limited, although I have been using C++Builder since version 3.

I have a project in C++Builder 2007 with a class having a property "aVers" returning the FileVersion in an AnsiString.
For certain values of FileVersion I want the application to show a message and close immediately after the OK button has been pressed. When I use the "Close()" function, the following message appears after I press OK: "Cannot change Visible in OnShow or OnHide." with the red dot and white cross in its window. After pressing OK again, the application is NOT closed.
To get it working I added a Timer component to the main Form with a 100 msec Interval. In the Timer function I call Close(). This setup works as I want it. But I have the feeling that it is not good practice...

The relevant code snippets follow.
Code:
  ...
    //                // this code is in the FormActivate function
    // get the version now
    //TRadio *VersObj;        // TRadio is defined in the Main Form header code.
    RadioObj = new TFreq;        // TFreq is a class derived from TRadio;
                    // retrieves the Version of App2 from
                    // "App2.exe". Makes use of "CreateProcess"
                    // and hides the console window when active.
    Version = RadioObj->aVers;
    delete RadioObj;
    RadioObj = NULL;

    if ((Version.AnsiPos("a")) || (Version.AnsiPos("b")))   {
        ShowMessage ("unsupported Version " + Version + ";\n"
        "          the application will exit.");
        //Timer1->Enabled = true;
        Close();
    }
    ...
Code:
    ...
    void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
    Close();
}
    ...

In this example, when I comment out "Close()" and uncomment "Timer1-> etc." it works fine; as shown it fails.

What can be the reason for the error message as described above and how should I tackle this problem? Your comments will be welcomed!

Alex314
 
The global Application Variable has a Terminate Function which might be what you are looking for.
 
Thanks! That does it. Things are simple if you happen to know them!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top