Solved

Execute procedure, wait until finished, resume.

Posted on 2000-05-05
4
414 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

820 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