Board index » cppbuilder » What is the best way to exit from within the main form constructor
William Charles Nickerson
CBuilder Developer |
William Charles Nickerson
CBuilder Developer |
What is the best way to exit from within the main form constructor2004-05-31 11:21:29 PM cppbuilder54 Hello What is the best way to exit the application if something is detected during the constructor of the main form (i.e. user is not authorized or something like that). What would be the repercussions of using exit? Ciao Bill |
JD
CBuilder Developer |
2004-06-01 12:01:17 AM
Re:What is the best way to exit from within the main form constructor
"William Charles Nickerson" < XXXX@XXXXX.COM >wrote:
QuoteWhat is the best way to exit the application if something is void __fastcall TForm1::Activate(TObject *Sender) { if( flag ) { MessageDlg( "No Way Jose!!", mtError, TMsgDlgButtons() << mbOK, 0 ); Close(); } } The result is that the user gets some visual feedback instead of launching the application and nothing (visually) happening. ~ JD |
William Charles Nickerson
CBuilder Developer |
2004-06-01 12:14:15 AM
Re:What is the best way to exit from within the main form constructor
Thanks JD
"JD" < XXXX@XXXXX.COM >wrote in message QuoteIt depends on how you code. I would set a flag and then in the immediately? Can you call Close () within the constructor? Quotevoid __fastcall TForm1::Activate(TObject *Sender) further messages at this point. Ciao Bill {smallsort} |
JD
CBuilder Developer |
2004-06-01 12:27:30 AM
Re:What is the best way to exit from within the main form constructor
"William Charles Nickerson" < XXXX@XXXXX.COM >wrote:
QuoteWhy would you wait until the OnActivate event? QuoteIs there a problem with terminating immediately? QuoteCan you call Close () within the constructor? { // finish constructing } else { Close(); } ~ JD |
William Charles Nickerson
CBuilder Developer |
2004-06-01 01:08:06 AM
Re:What is the best way to exit from within the main form constructor
Thanks JD
I appreciate the insight and info. I plan to follow your suggestion to move it to the OnActivate event. Bill |
Remy Lebeau (TeamB)
CBuilder Developer |
2004-06-01 06:25:43 AM
Re:What is the best way to exit from within the main form constructor
"William Charles Nickerson" < XXXX@XXXXX.COM >wrote in message
QuoteWhat is the best way to exit the application if something is QuoteWhat would be the repercussions of using exit? Gambit |
Remy Lebeau (TeamB)
CBuilder Developer |
2004-06-01 06:27:58 AM
Re:What is the best way to exit from within the main form constructor
"JD" < XXXX@XXXXX.COM >wrote in message
QuoteIt depends on how you code. I would set a flag and then { if( some condition ) { ::MessageBox(NULL, "No Way Jose!!", "ERROR!", MB_OK); Application->ShowMainForm = false; Application->Terminate(); } } Even better would be if you do your validation inside of WinMain() directly before the VCL even begins creating forms at all. Gambit Gambit |
William Charles Nickerson
CBuilder Developer |
2004-06-01 09:53:23 PM
Re:What is the best way to exit from within the main form constructor
Thanks Remy
That is the information that I need. Ciao Bill "Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message Quote
|
Mark Jacobs
CBuilder Developer |
2004-06-01 10:42:41 PM
Re:What is the best way to exit from within the main form constructor
"William Charles Nickerson" < XXXX@XXXXX.COM >wrote in message news:40bb4d79$ XXXX@XXXXX.COM ...
QuoteWhat is the best way to exit the application if something is detected and OnCloseQuery events, so I use the following method (invented by me and free for general use - cheeky). Put a timer on your form with an interval of 300 ms and enabled as false. Then :- //--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { static bool ever_called=false; if (ever_called) return; ever_called=true; if (the conditions that require the program to close are met) { Timer1->Enabled=true; return;} // ... any other init stuff can go here } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { Timer1->Enabled=false; Close(); } //--------------------------------------------------------------------------- HTH -- Mark Jacobs DK Computing www.dkcomputing.co.uk markj atty critical dotty co dotty uk |