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

怎甘沉沦 提交于 2019-12-07 06:16:52

问题


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;

回答1:


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?




回答2:


According to this article here: http://edn.embarcadero.com/article/32756 web browsers don't allow threading via ActiveX. However that still doesn't explain why it doesn't work when I put it in a C# application.



来源:https://stackoverflow.com/questions/7935870/delphi-thread-not-executing-in-activex-form-but-does-elsewhere

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!