> Jamie,
> Just a guess, could it be that the call:
> result := FAppSession.requestResult;
> throws an exception ?
> that would explain why Synchronize isnt called...
> again: just a guess i havent really looked carefully
> "Jamie" <jami...@zfree.co.nz> wrote in message
> news:arh8ec$n4c$1@lust.ihug.co.nz...
> > Hi all,
> > I've written a COM object that gets called from a VBA macro in Word.
I've
> > created a thread that this object uses, and when the thread finishes I
> want
> > to call a method in the COM object. The problem I'm having is that when
> the
> > thread finishes, the OnTerminate event isn't triggered, and if I try to
> use
> > 'Synchronize' on a thread method to get into the context of the main
> thread,
> > the method isn't called. If I try to call the COM object method directly
> > from the thread, it doesn't work either.
> > I'm new to threading in Delphi, so I may be missing something obvious
> here.
> > I've included an edited code sample.
> > Any help would be much appreciated.
> > Many thanks,
> > Jamie
> > [snip]
> > type
> > TOfficeIntegration = class(TAutoObject, IOfficeIntegration)
> > protected
> > procedure showSearch; stdcall;
> > [snip]
> > private
> > [snip]
> > procedure startRequestThread;
> > procedure requestTerminated(Sender: TObject);
> > end;
> > TRequestThread = class(TThread)
> > private
> > [snip]
> > protected
> > procedure Execute; override;
> > procedure doRequest;
> > published
> > [snip]
> > end;
> > implementation
> > uses ComServ;
> > [snip]
> > procedure TOfficeIntegration.showSearch;
> > { Shows the 'Search' dialog. }
> > begin
> > {Defer to RPC server}
> > appSession.showSearch;
> > startRequestThread;
> > end;
> > procedure TOfficeIntegration.startRequestThread;
> > var
> > requestThread: TRequestThread;
> > begin
> > { Create thread }
> > requestThread := TRequestThread.Create(True);
> > requestThread.OnTerminate := requestTerminated;
> > requestThread.Resume;
> > end;
> > procedure TOfficeIntegration.requestTerminated(Sender: TObject);
> > var
> > requestThread: TRequestThread;
> > resultString: String;
> > begin
> > ShowMessage('Got thread terminated!');
> > end;
> > [snip]
> > { TRequestThread }
> > procedure TRequestThread.doRequest;
> > begin
> > ShowMessage('Doing request: ' + FResultString);
> > end;
> > procedure TRequestThread.Execute;
> > var
> > result: String;
> > begin
> > result := FAppSession.requestResult;
> > if Length(result) > 0 then begin
> > FResultString := result;
> > end;
> > Synchronize(doRequest);
> > end;
> > [snip].