Board index » delphi » How does the 'real' developers manage this ?

How does the 'real' developers manage this ?

Hello,

I have an automation server and a client.
In my server, I start my client application and loads a file for that client
as follows :

Procedure Server.StartClient(filename_arg : string);
var
clientobject : IDispatch;
begin
    clientobject := CreateComObject(CLASS_Client) as IClient;
    clientobject.open(filename_arg);
end;

So far so good.
When the software starts the CreateComObject, it starts the client
application and processes the FormCreate.  While this process is starting
up, the server receives a value for the clientobject and starts the second
statement clientobject.open(...).

When the software starts the open(...) method, the previous FormCreate of
the client is in my case not yet finished (e.g. on a slow PC) and has
therefore no Application.MainForm.Handle.

What happens is : because you have no MainForm.Handle, everything you do in
the open(...) method, riscs not to be displayed on the clients MainForm.

My question is : do I have to put a 'wait' between the CreateComObject and
the clientobject.open() or is there another way to fix this ?  I suppose
other developers have already encountered such a behaviour...

Thanx for your help,

--
Stefan De Grande
sdg<noSpam>@hemmis.be

 

Re:How does the 'real' developers manage this ?


This behavior is due to COM STA threading mechanics. What you can do instead
is create a waiting loop like this:

procedure WaitTillAppIsReady;
begin
  while not (AppIsReady) do
   Application.ProcessMessages;
end;

And somewhere in you main form, set the AppIsReady variable at the
appropriate time.

Then in your critical COM method, call WaitTillAppIsReady as the first
statement.

--
have fun
Binh Ly
http://www.techvanguards.com

Quote
"Stefan" <sdg_rem...@hemmis.be> wrote in message news:3bbafbb3_1@dnews...
> Hello,

> I have an automation server and a client.
> In my server, I start my client application and loads a file for that
client
> as follows :

> Procedure Server.StartClient(filename_arg : string);
> var
> clientobject : IDispatch;
> begin
>     clientobject := CreateComObject(CLASS_Client) as IClient;
>     clientobject.open(filename_arg);
> end;

> So far so good.
> When the software starts the CreateComObject, it starts the client
> application and processes the FormCreate.  While this process is starting
> up, the server receives a value for the clientobject and starts the second
> statement clientobject.open(...).

> When the software starts the open(...) method, the previous FormCreate of
> the client is in my case not yet finished (e.g. on a slow PC) and has
> therefore no Application.MainForm.Handle.

> What happens is : because you have no MainForm.Handle, everything you do
in
> the open(...) method, riscs not to be displayed on the clients MainForm.

> My question is : do I have to put a 'wait' between the CreateComObject and
> the clientobject.open() or is there another way to fix this ?  I suppose
> other developers have already encountered such a behaviour...

Other Threads