2

I have a Delphi7 program which implements a com server. Recently the time for program initialisation to complete has increased somewhat due to some new database queries. What I mean by program initlisation is the time it takes for the program to be able to process the incoming com calls in a meaningful way. My question is how I can handle incoming com calls when the program is not properly initialised yet. Discarding the information contained in the call is not an option, the call needs to wait for the program to initialise. Will a simple while loop using a boolean initialisation variable be sufficient? I ask because I read that com calls are executed in the main VCL thread, which would suggest that a while loop would cause the program to hang (The initialisation takes place in the VCL thread as well).

Mutexes cannot be used to waitfor code executing within the same thread, right?

To put it another way, does a com call interupt execution of the (com server's) VCL thread until it is done or how does this concurrent execution of code within the same thread work? Thanks for taking the time.

2
  • COM doesn't mind waiting. Why do you want to help? Don't help. Commented Nov 17, 2012 at 16:29
  • But if a com call executes within the vcl thread and initialisation takes place within the VCL thread then won't a while loop block that thread and cause initilisation not to finish ever? When windows starts a delphi program containing a com server, which sections (initialisation sections, form creates) are executed before the com function is called? If I know that then I can make sure a com function will never be executed before initialisation is complete. Commented Nov 18, 2012 at 16:17

2 Answers 2

1

Move your database logic out of the main thread so it is not blocked anymore.

Sign up to request clarification or add additional context in comments.

2 Comments

The initialisation relies on displaying information on the GUI. If I move it to a different thread I will either need to call synchronise (I guess) or use messages to avoid access violations, since the VCL components are not thread safe (not realy sure about that part, but its how I understand the VCL to work). If this premise is correct then won't either of these mechanisms hang the program because the VCL thread is stuck in the com call? Hmmm. Or could I use a mutex and waitfor... in this scenario?
Then decouple your initialization from your UI. Have the initialization store the information in memory somewhere and move on, and then have the UI pick up that information and display it at its leisure.
0

COM server (EXE) waits Applcation.Run before return the control flow to the COM client, so all forms and data modules should be initialized.

However, when a form creates another OLE object (i.e. open Word doc in FormCreate() event handler) this may interrupt waiting and return control to the COM client immediately.

Try to check all initialization code of the forms created before Applcation.Run to localize the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.