Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Execute procedure, wait until finished, resume.

Posted on 2000-05-05
4
Medium Priority
?
428 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

722 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