Solved

Processing to occur right after displaying form

Posted on 1998-04-12
1
133 Views
Last Modified: 2010-04-06
I often find myself in the situation where I wish to do some processing immediately after displaying a form.  

Steps I wish to follow:

  1 - Modal Form is called by main application
  2 - Modal form is fully displayed and visible by user
  3 - Processing occurs here...

The TForm event OnShow won't show my form before the processing is done.  

Thank you.
0
Comment
Question by:ymailhot
1 Comment
 
LVL 3

Accepted Solution

by:
KE earned 100 total points
ID: 1361472
You can actually not process any code after a call to the showmodal method. Showmodal will halt the current thread until the ModalResult is<>0.
You can only process code before setting the form in a modal state. If the code is concerning the form, you may want to make a special method in your form object - which initializes your form and call's the showModal method.
Ex:

MyForm = class(TForm)
bla, bla,
Public
  // This line is inserted in to your existing form declaration
  Function MyNewSpecialMethod( MyParams ) : TModalResult;
End;

Function MyForm.MyNewSpecialMethod : TModalResult;
begin
  <Initialize here>
  Result := ShowModal;
  Case result of
    bla, bla,
  end;
end;

Function MyForm.AnotherNewSpecialMethod : TModalResult;
begin
  <Initialize here>
  Repeat
     // Make the Controls work
     Application.ProcessMessages;

    <Do something here>

    // Let the thread sleep a little so you dont spend all the CPU time in this loop;
    Sleep( 100 );
  Until ModalResult<>0;
  Result := ModalResult;
end;

If it's necessary to do processing after a showModal try to use the events of your controls on the form, or if necessary use a TTimer to trigger an event.
Another way is to create a new thread, but i don't think it's what your'e looking for.


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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