Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - Thread not executing in ActiveX form - but does elsewhere

I have a thread, called TAlertThread. The thread interacts with its owner by triggering events. For example, when certain data is available inside the thread, it sets some temp variables and calls Synchronize(UpdateAlert) which in turn triggers the appropriate event.

Now the thread works perfectly in any standard windows application. My problem is when I put that thread inside of an ActiveX form (TActiveForm). The ActiveX control (aka COM object) is then embedded inside of a Windows Desktop Gadget (via HTML / Javascript). I also have experience with this, the gadget is not the issue. The ActiveX component works fine in its destination, except the thread is never executed. It's even being called EXACTLY the same way as I called it from the App.

Is this some limitation with ActiveX, blocking threads from executing? I wouldn't think so, because other things that require threads internally (such as TADOConnection) work. I am in fact properly calling CoInitialize and CoUninitialize appropriately. Again, works perfect in an application, but does not work at all in ActiveX.

Here is how I call this thread...

procedure TRMPDashXS.ExecThread;
begin
  //Thread created suspended
  lblStatus.Caption:= 'Executing Thread...'; 
  fThread:= TAlertThread.Create(fConnStr); //fConnStr = connection string
  fThread.Priority:=      tpIdle;
  fThread.OnConnect:=     Self.ThreadConnected;
  fThread.OnDisconnect:=  Self.ThreadDisconnected;
  fThread.OnBegin:=       Self.ThreadStarted;
  fThread.OnFinish:=      Self.ThreadFinished;
  fThread.OnAlert:=       Self.ThreadAlert;
  fThread.OnAmount:=      Self.ThreadAmount;
  fThread.Resume; //Execute the thread
end;
like image 574
Jerry Dodge Avatar asked Oct 28 '11 23:10

Jerry Dodge


1 Answers

I suspect this might describe exactly what you're experiencing in your version of Delphi:

  • http://soft-haus.com/blog/2009/02/10/codegear-borland-activex-threading-synchronization-problems/

    which references the same article you cited:

  • http://edn.embarcadero.com/article/32756

I'm not sure if that helps ... but I hope it does. At least a little :)

PS: Is there any particular reason you have to use Com/ActiveX and/or TActiveForm?

like image 82
paulsm4 Avatar answered Nov 08 '22 21:11

paulsm4