barnarp
asked on
Bypassing FormShow(Sender: TObject) Event
Hi,
I check for a certain condition on application startup in the FormCreate procedure. If the condition is not met, I do not want the applkication to the show the form by running FormShow. What code can I use to show the form OR not show the form depending on the condition being true or false in FormCreate?
Regards
Pierre
I check for a certain condition on application startup in the FormCreate procedure. If the condition is not met, I do not want the applkication to the show the form by running FormShow. What code can I use to show the form OR not show the form depending on the condition being true or false in FormCreate?
Regards
Pierre
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it is the main form, but when I use Application.ShowMainForm:= false; in the Formcreate procedure, it still runs the FormShow procedure.
Code:
procedure TfrmMain.FormCreate(Sender : TObject);
begin
if (paramstr( 7 ) = '') then
begin
Messagedlg('Please select a valid number.', mtError,[mbOK],0 );
Application.Terminate;
Application.ShowMainForm:= false;
Application.ProcessMessage s;
Exit;
end;
Still goes into Formshow.
Code:
procedure TfrmMain.FormCreate(Sender
begin
if (paramstr( 7 ) = '') then
begin
Messagedlg('Please select a valid number.', mtError,[mbOK],0 );
Application.Terminate;
Application.ShowMainForm:=
Application.ProcessMessage
Exit;
end;
Still goes into Formshow.
why not place your check into the project-source like
...
Application.Initialize;
if (paramstr( 7 ) <> '') then
begin
Messagedlg('Please select a valid number.', mtError,[mbOK],0 );
Application.CreateForm(TFo rm1, Form1);
Application.Run;
end;
...
just from head
meikl ;-)
...
Application.Initialize;
if (paramstr( 7 ) <> '') then
begin
Messagedlg('Please select a valid number.', mtError,[mbOK],0 );
Application.CreateForm(TFo
Application.Run;
end;
...
just from head
meikl ;-)
The problem may be elsewhere...I tried your code and it works as expected here. The dialog pops up, and then the application ends. I also found I didn't need the "processmessages" call.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the comments. I also suspect that the problem could be elsewhere. kretzschmar , I tried your solution and it worked 100%.
>I tried your solution and it worked 100%.
well, nice to read :-))
if you come to the grading i recommend to split the points between me and
LRHGuy, because his suggestions should be also work.
in case, if you find the problem, so that LRHGuy suggestion will work,
and u use it also, then LRHGuy deserves all points, of course
meikl ;-)
well, nice to read :-))
if you come to the grading i recommend to split the points between me and
LRHGuy, because his suggestions should be also work.
in case, if you find the problem, so that LRHGuy suggestion will work,
and u use it also, then LRHGuy deserves all points, of course
meikl ;-)
I have used this in the project unit. If a parameter is sent the form does not display.
If paramcount <> 0 then Application.CreateForm(TFo rm1, Form1);
If a parameter is sent I then process them inside the formcreate event.
If you need to read values off of the form then the form will have to be visible. I have set the width and height for the form to 0 and placed the form in the top left coner of the screen. It will flash in the top corner as it processes it's data before closing. I found this better than having the form pop-up in the middle before closing.
Randy
If paramcount <> 0 then Application.CreateForm(TFo
If a parameter is sent I then process them inside the formcreate event.
If you need to read values off of the form then the form will have to be visible. I have set the width and height for the form to 0 and placed the form in the top left coner of the screen. It will flash in the top corner as it processes it's data before closing. I found this better than having the form pop-up in the middle before closing.
Randy
>> >I tried your solution and it worked 100%.
:))
declare a public variable in your main form (example - gboolOK: boolean;)
in the form create event set this variable to True or False.
in the dpr:
Application.Initialize;
Application.CreateForm(TFo rm1, Form1);
if Form1.gboolOK then
Application.Run
else
Form1.Free;
but maybe you have already done something like that ...
:))
declare a public variable in your main form (example - gboolOK: boolean;)
in the form create event set this variable to True or False.
in the dpr:
Application.Initialize;
Application.CreateForm(TFo
if Form1.gboolOK then
Application.Run
else
Form1.Free;
but maybe you have already done something like that ...
please forget my last post .. i must be tired (i didn't see that you are checking a parameter value ...)
You can disable the call to the FormShow event by setting OnFormShow to nil:
OnFormShow:=nil;
If you do that in FormCreate, then the FormShow event you've defined will not be called.
But, that does not stop the form from being shown. Depending on the type of form, and how it's being called, you might be able to set visible to false. Is this the main form?