Solved

Execute procedure, wait until finished, resume.

Posted on 2000-05-05
4
420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 225
Performance of SQL statement 37 147
How to Get Images From Server to Client using App Tethering 1 57
Delphi Firemonkey send email on Android 1 80
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
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…

734 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