Board index » cppbuilder » Application->Terminate() <-- in constructor...

Application->Terminate() <-- in constructor...


2004-10-27 09:31:39 PM
cppbuilder14
Hi All, I'd like to terminate application in constructor if some condition
is true.
and I do
if(condition)
Application->Terminate();
well it sort of terminates, at least doesn't go any further,
but the process stays forever. well I don't know forever or not, coz have
never tried, but for a long
time anyway...
 
 

Re:Application->Terminate() <-- in constructor...

George wrote:
Quote
Hi All, I'd like to terminate application in constructor if some condition
is true.
and I do
if(condition)
Application->Terminate();

well it sort of terminates, at least doesn't go any further,
but the process stays forever. well I don't know forever or not, coz have
never tried, but for a long
time anyway...




Application->Terminate() from the main form constructor works fine for
me although it is not very elegant. I only do that for debugging purpose
or as a quick temporary solution. What it does for me is that I see the
form appear on screen for a split second than disappear as the
application terminates.
For a more elegant solution you should try to cancel away program
startup directly from the WinMain fonction (Project1.cpp if you don't
change the projet name, or <your project name>.cpp). Simply, check you
condition form the very beginning of the function, before the BCB forms
creation stuff, and if you condition is not satisfactory than simple
return. The application terminates as soon as the WinMain function
returns (the Application->Run() function in WinMain does not return
until the main form was closed). Since no form is created, the user gets
no clue that the program ever started. This is good, for example, if you
want to prevent two instances of your program from running at once.
 

Re:Application->Terminate() <-- in constructor...

Hi Tom, thanks for answering,
the problem is that I can't check it in project's .cpp file...
because I'm checking something that is done in form's constructor....
and well if it's not done correctly I just need to quick.
"Tom|420" < XXXX@XXXXX.COM >wrote in message
Quote
George wrote:

>Hi All, I'd like to terminate application in constructor if some
condition
>is true.
>and I do
>if(condition)
>Application->Terminate();
>
>well it sort of terminates, at least doesn't go any further,
>but the process stays forever. well I don't know forever or not, coz
have
>never tried, but for a long
>time anyway...
>
>
>
>

Application->Terminate() from the main form constructor works fine for
me although it is not very elegant. I only do that for debugging purpose
or as a quick temporary solution. What it does for me is that I see the
form appear on screen for a split second than disappear as the
application terminates.

For a more elegant solution you should try to cancel away program
startup directly from the WinMain fonction (Project1.cpp if you don't
change the projet name, or <your project name>.cpp). Simply, check you
condition form the very beginning of the function, before the BCB forms
creation stuff, and if you condition is not satisfactory than simple
return. The application terminates as soon as the WinMain function
returns (the Application->Run() function in WinMain does not return
until the main form was closed). Since no form is created, the user gets
no clue that the program ever started. This is good, for example, if you
want to prevent two instances of your program from running at once.
 

{smallsort}