Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Execute procedure, wait until finished, resume.

Posted on 2000-05-05
4
Medium Priority
?
431 Views
Last Modified: 2010-04-04
I have a procedure that loads settings for colors...

I call the procedure, then I use RichEdit1.Selattributes.Color like so:

MyProcedure; {Gets MyInt - Color for text}
RichEdit1.Selattributes.Color := MyInt;
RichEdit1.Lines.Add('MyText');

The problem is, the "MyProcedure" isn't done before the app moves to the next line!

I've tried:
MyProcedure; {Gets MyInt - Color for text}
Application.ProcessMessages;
RichEdit1.Selattributes.Color := MyInt;
RichEdit1.Lines.Add('MyText');


But that doesn't help!

How can I call the procedure, WAIT until it's finished, then call the rest without writing an entire new procedure?


-Psylord
0
Comment
Question by:Psylord
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
kotik earned 0 total points
ID: 2783770
Hi!
Do you use another thread in your procedure? If not - your app cannot move to the next line until MyProc is finished.
If you are using threads you can use different synchronization objects (Events, Mutexes, Semaphores) to wait until the proc is finished.

F.e.:
uses
  SyncObjs;
....
{ Create Event somewhere }
  TermEvent := TEvent.Create(nil, True, False, '');

{ In the end of MyProcedure add this code: }
    TermEvent.SetEvent;

{ Change the call as this }
MyProcedure; {Gets MyInt - Color for text}
TermEvent.WaitFor(WAIT_TIMEOUT); // or INFINITE
RichEdit1.Selattributes.Color := MyInt;
RichEdit1.Lines.Add('MyText');

Regadrs,
  Kot




0
 

Author Comment

by:Psylord
ID: 2783776
Thanks!

I think the problem is that I had it in the create event (when the form might not even have a handle yet!)..

But this code looks useful.... Thanks!
0
 
LVL 2

Expert Comment

by:kotik
ID: 2783780
And don't forget to destroy the event object in the end:

TermEvent.Free;
0
 
LVL 2

Expert Comment

by:hhamster
ID: 2783883
I don't agree with you. It must do 'MyProcedure' 1st, and then do the rest. Try debugging and look how it moves. It can only do so if 'MyProcedure' is a thread.

But where's the return value of it? Shouldn't it the 1st line say:
MyInt := MyProcedure;
and then use the value in the next line.
0

Featured Post

Independent Software Vendors: 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

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…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

824 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