Solved

Execute procedure, wait until finished, resume.

Posted on 2000-05-05
4
396 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
Comment Utility
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
Comment Utility
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
Comment Utility
And don't forget to destroy the event object in the end:

TermEvent.Free;
0
 
LVL 2

Expert Comment

by:hhamster
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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