Solved

Bypassing FormShow(Sender: TObject) Event

Posted on 2004-08-26
11
353 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:barnarp
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11901848
I think you have two different issues.

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?
0
 
LVL 7

Assisted Solution

by:LRHGuy
LRHGuy earned 50 total points
ID: 11901909
If it's the main form, you can use:

Application.ShowMainForm:=false;
0
 

Author Comment

by:barnarp
ID: 11902022
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.ProcessMessages;
      Exit;
      end;

Still goes into Formshow.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 11902127
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(TForm1, Form1);
     Application.Run;
  end;
...

just from head

meikl ;-)
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11902197
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.
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 11902336
ehm sorry,
should be

...
  Application.Initialize;
  if (paramstr( 7 ) <> '') then
  begin
     Application.CreateForm(TForm1, Form1);
     Application.Run;
  end
  else
      Messagedlg('Please select a valid number.', mtError,[mbOK],0 );
...

meikl ;-)
0
 

Author Comment

by:barnarp
ID: 11902703
Thanks for the comments. I also suspect that the problem could be elsewhere. kretzschmar , I tried your solution and it worked 100%.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 11903115
>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 ;-)
0
 

Expert Comment

by:ISGDude
ID: 11905839
I have used this in the project unit.  If a parameter is sent the form does not display.

If paramcount <> 0 then  Application.CreateForm(TForm1, 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
0
 
LVL 6

Expert Comment

by:bpana
ID: 11908028
>> >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(TForm1, Form1);
  if Form1.gboolOK then
    Application.Run
  else
    Form1.Free;

but maybe you have already done something like that ...
0
 
LVL 6

Expert Comment

by:bpana
ID: 11908123
please forget my last post .. i must be tired (i didn't see that you are checking a parameter value ...)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: how to send PJL commands to printer 3 99
Magic Software info 18 131
Delphi inherited method 6 70
update joined tables 2 46
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question