Solved

Processing to occur right after displaying form

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now