Modal Form OnShow Event

I have a Delphi 4 app which shows a modal form from my main form when a button is clicked. I am having a problem with the modal form's OnShow event. Using debugging I found that the modal form's OnShow event only gets called the first time I call the ShowModal method. On all subsequent calls, the OnShow event is not triggered allthough the OnActivate event is triggered. Any suggestions on what might be causing this ?
-Thanks
-Mike
mferdockAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
do you call form2.hide before try to call onshow the subsequent times?

0
rwilson032697Commented:
This will happen is the form has not been closed once you are finished with it, or you are somehow calling ShowModal more than once to invoke the form.

Once the form is shown then subsequent calls to ShowModal will not call the OnShow event.

Cheers,

Raymond.
0
intheCommented:
from delphi help:
->
OnShow Occurs when the form is shown (that is, when its Visible property is set to True).
<-

so on your form2 onclose event call form2.visible := false;
then when form1 calls the form2.showmodal again the onshow event will be fired.

0
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

geobulCommented:
Hi Mike,

You can solve your problem in the calling form this way:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.ShowModal;
  Form2.Hide;
end;

if you do not want to change the form2.

Regards, Geo
0
mferdockAuthor Commented:
I have tried calling the Hide method before the ShowModal method and also after the ShowModal method but with no success. I use SendMessage to send a WM_CLOSE message to the modal form to close it once I am done with the form. When I use the debugger to check the visible property for the modal form before calling the ShowModal method, the property is False.
I could swear that it use to work before I installed Delphi 4 update pack 3 on my PC, but since then the ONShow event does not appear to be working correctly. Anyone know of any problems with update pack 3 that might cause this ? Any other suggestions ?
-Mike
0
geobulCommented:
Hi Mike,

Possible solution is to create the modal form every time you click the button and free after (or on) closing it. If it's not a problem to your project, of course.

procedure TForm1.Button1Click(Sender: TObject);
begin
  Application.CreateForm(TForm2, Form2); { this line is removed from your project unit }
  Form2.ShowModal;
  Form2.Release;
end;

or:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Application.CreateForm(TForm2, Form2); { this line is removed from your project unit }
  Form2.ShowModal;
end;

{ Modal form OnClose event }
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

Regards, Geo
0
karooCommented:
Mike,

weird problem,

hmmm, try the following:

private
  procedure MyFormShow(Sender: TObject);
...

procedure TForm1.FormCreate(Sender: TObject);
begin
  OnShow := MyFormShow;
end;

procedure TForm1.MyFormShow(Sender: TObject);
begin
  //your OnShow code here
end;

Regrads
Ben;-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mferdockAuthor Commented:
I am not sure why assigning your own event handler to the form's OnShow event handler would work, but I tried this and it does work. If any one else has any comments on why this works feel free to chime in.
Thanks Ben...

-Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.