Solved

Processing to occur right after displaying form

Posted on 1998-04-12
1
131 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

831 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