ActiveX事件不触发 ( 积分: 200 )

  • 主题发起人 主题发起人 Toysun
  • 开始时间 开始时间
T

Toysun

Unregistered / Unconfirmed
GUEST, unregistred user!
我实在找不到解决方法了,请大家帮忙:

我写了一个组件,工作很正常,转换为ActiveX Control后有些事件不触发
在create里面,我用了一下代码:

FServer := TIdUDPServer.Create(nil);
FServer.ThreadedEvent:=False;
with FServer do
begin
DefaultPort := port;
//编译为组件,udpread正常工作,
//编译为ActiveX后不进入udpread过程
OnUDPRead := UDPRead;
try
Active := true;
except
Exit;
end
{try}
end
{with}
 
我实在找不到解决方法了,请大家帮忙:

我写了一个组件,工作很正常,转换为ActiveX Control后有些事件不触发
在create里面,我用了一下代码:

FServer := TIdUDPServer.Create(nil);
FServer.ThreadedEvent:=False;
with FServer do
begin
DefaultPort := port;
//编译为组件,udpread正常工作,
//编译为ActiveX后不进入udpread过程
OnUDPRead := UDPRead;
try
Active := true;
except
Exit;
end
{try}
end
{with}
 
Regardless of the state of
ThreadedEvent, TIdUDPServer uses a thread to work. If ThreadedEvent is
False, then Synchronize is used to perform the notification. It is my
understanding that Synchronize does not work correctly in a DLL. Peter
Below has provided an alternative that works better. Search the
newsgroups for his name and "Syncrhonize".

Good luck, Brian
 
{== D6DLLSynchronizer =================================================}
{: This unit handles the D6 synchronize problem in DLLs
@author Dr. Peter Below
@desc Version 1.0 created 3 November 2001<BR>
Current revision 1.0<BR>
Last modified 3 November 2001<P>
Usage: <BR>
Just add this unit to the DLL project, make sure you do not modify
the WakeMainThread global event yourself elsewhere. }
{======================================================================}
Unit D6DLLSynchronizer;

Interface

Implementation
Uses Windows, Messages, classes;

Type
TSyncHelper = Class
Private
wnd: HWND;
Procedure MsgProc( Var msg: TMessage );
Procedure Wakeup( sender: TObject );
Public
Constructor Create;
Destructor Destroy
override;
End;

Var
helper: TSyncHelper = nil;

{ TSyncHelper }

Constructor TSyncHelper.Create;
Begin
inherited;
wnd:= AllocateHWnd( msgproc );
WakeMainThread := Wakeup;
End;

Destructor TSyncHelper.Destroy;
Begin
WakeMainThread := nil;
DeallocateHWnd( wnd );
inherited;
End;

Procedure TSyncHelper.MsgProc(Var msg: TMessage);
Begin
If msg.Msg = WM_USER Then
CheckSynchronize
Else
msg.result := DefWindowProc( wnd, msg.msg, msg.WParam, msg.LParam );
End;

Procedure TSyncHelper.Wakeup(sender: TObject);
Begin
PostMessage( wnd, WM_USER, 0, 0 );
End;

Initialization
helper:= TSyncHelper.Create;
Finalization
helper.free;
End.
 
接受答案了.
 

Similar threads

回复
0
查看
1K
不得闲
D
回复
0
查看
842
DelphiTeacher的专栏
D
D
回复
0
查看
848
DelphiTeacher的专栏
D
D
回复
0
查看
683
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部