Exit(0) in "FormActivate" produces exception & error Cannot change Visible in Ohshow or OnHide
I inherited a program that I am now responsible for and in the "TfrmMain::FormActivate" routine there are a few places that check for an instrument alive on the GPIB bus and if its not, an error is displayed and then the code performs an "exit(0)". When this happens and I'm in the debugger I get the following error message:
"Project RF_CCA_Ttest.exe raised exception class EInvalidOperation with message 'Cannot change Visible in OnShow or OnHide'. Process stopped. Use step or Run to Continue."
I am in the FormActivate event procedure not an OnShow or OnHide. Anyway how can I shut the program down from within the FormActivate event procedure?