Delphi - 线程不在ActiveX窗体中执行 - 但在其他地方 [英] Delphi - Thread not executing in ActiveX form - but does elsewhere

查看:254
本文介绍了Delphi - 线程不在ActiveX窗体中执行 - 但在其他地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个线程叫做TAlertThread。线程通过触发事件与其所有者进行交互。例如,当某些数据在线程内部可用时,它会设置一些临时变量并调用Synchronize(UpdateAlert),从而触发相应的事件。



完美的在任何标准Windows应用程序。我的问题是当我将该线程放在ActiveX窗体(TActiveForm)中时。然后将ActiveX控件(又名COM对象)嵌入到Windows桌面小工具(通过HTML / Javascript)中。我也有经验,这个小工具不是问题。 ActiveX组件在其目标中工作正常,除了线程从不执行。它甚至被称为完全相同的方式,从我从应用程序中调用它。



这是ActiveX的一些限制,阻止线程执行?我不会这样想,因为其他需要内部线程的东西(如TADOConnection)工作。实际上我恰当地调用了CoInitialize和CoUninitialize。再次,在应用程序中工作完美,但在ActiveX中根本不起作用。



这是我如何调用这个线程...

  TRMPDashXS.ExecThread; 
begin
//创建挂起的线程
lblStatus.Caption:='执行线程...';
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; //执行线程
end;


解决方案

我怀疑这可能会描述你正在遇到的在您的Delphi版本中:





我不知道这是否有帮助...但我希望它有效。至少有一点:)



PS:
有什么特别的原因你使用Com / ActiveX和/或TActiveForm ?


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;

解决方案

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

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?

这篇关于Delphi - 线程不在ActiveX窗体中执行 - 但在其他地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆