Close Form in OnShow

I have a dll that does certain modem communication processes and thus displays updates via modal forms.

The process is started in the OnShow of a modal form and can terminate depending on certain conditions after which I display a status (on the modal form) and then it terminates after a short time. (same as a normal modem connection dialog box does with for example closing connection... etc.)

??What can I do to close the modal form in the OnShow event, or workaround except posting a message to myself to start the process.
Who is Participating?
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.

Have you tried:


Rob ;-)

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
Do something like

  ModalResult := mrOk;


  ModalResult := mrCancel;
karooAuthor Commented:
I tried Sendmessage(Self.Handle, WM_CLOSE, 0, 0) in a small app in the OnShow event, it doesn't work.
Did not try WM_DESTROY because that will mess with the inherited close from my base form which needs to be executed in the OnClose, anyway it is my callers job to free the form and.

Tried it(didn't work), I think that setting the modalresult is esentially the same as close for a modal form and that the Close method is called in the forms vcl unit.

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

karooAuthor Commented:

this works:
Sendmessage(Application.Handle, WM_CLOSE, 0, 0);

obviously i have to pass the Applications handle and not the Modal forms handle

Thanks for the help just post an answer and i will award the points.

karooAuthor Commented:

accepted the comment as the answer:)
Glad it helped
Rob :-)
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

From novice to tech pro — start learning today.