COM自定义事件问题请教 ( 积分: 100 )

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

tty0819

Unregistered / Unconfirmed
GUEST, unregistred user!
进程内服务自定义事件问题
unit Isendp;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
ComObj, ActiveX, AxCtrls, Classes, cgamesend_TLB, StdVcl;

type
TTmysend = class(TAutoObject, IConnectionPointContainer, ITmysend)
private
{ Private declarations }
FConnectionPoints: TConnectionPoints;
FConnectionPoint: TConnectionPoint;
FEvents: ITmysendEvents;
{ note: FEvents maintains a *single* event sink. For access to more
than one event sink, use FConnectionPoint.SinkList, and iterate
through the list of sinks. }
public

procedure Initialize; override;
protected
{ Protected declarations }
property ConnectionPoints: TConnectionPoints read FConnectionPoints
implements IConnectionPointContainer;
procedure EventSinkChanged(const EventSink: IUnknown); override;
procedure showme; safecall;

procedure sss(x:integer);
end;

implementation

uses ComServ,csendformp;

procedure TTmysend.EventSinkChanged(const EventSink: IUnknown);
begin
FEvents := EventSink as ITmysendEvents;
end;

procedure TTmysend.Initialize;
begin
inherited Initialize;
csend.Onretucmd:=self.sss;
FConnectionPoints := TConnectionPoints.Create(Self);
if AutoFactory.EventTypeInfo <> nil then
FConnectionPoint := FConnectionPoints.CreateConnectionPoint(
AutoFactory.EventIID, ckSingle, EventConnect)
else FConnectionPoint := nil;
end;

procedure TTmysend.sss(x:integer);
begin
if FEvents<>nil then
FEvents.returncmd(x);
end;

procedure TTmysend.showme;
begin
//csend:=Tmyclss.Create;
sendform:=Tsendform.Create(nil);
sendform.ShowModal;
end;

initialization
TAutoObjectFactory.Create(ComServer, TTmysend, Class_Tmysend,
ciMultiInstance, tmApartment);
end.
-------------------------------
unit csendformp;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Isendp,listsendp;

type

Trusercmd = procedure(x:integer) of object;
Tmyclss=class

private
FOnretucmd: Trusercmd;
protected
published
property Onretucmd: Trusercmd read FOnretucmd write FOnretucmd;
end;
type


Tsendform = class(TForm)

Button1: TButton;

procedure Button1Click(Sender: TObject);
private
// constructor Create(AOwner:TComponent); Overvide;
//procedure sss(x:integer);
protected

{ Private declarations }
public


test1:tlistsend;
procedure sss(x:integer);
constructor Create(AOwner: TComponent); overload; override;
end;

var
sendform: Tsendform;
csend: Tmyclss;

implementation

{$R *.dfm}
constructor Tsendform.Create(AOwner: TComponent);
begin
csend:=Tmyclss.Create;
inherited Create(AOwner);

end;

procedure Tsendform.sss(x:integer);
begin

self.Button1.Caption:=inttostr(x);
end;

procedure Tsendform.Button1Click(Sender: TObject);

begin
//csend.Onretucmd:=self.sss;
test1:=tlistsend.Create(false);

end;

initialization

end.
--------------------------------
unit listsendp;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type

tlistsend = class(TThread)
private

{ Private declarations }
protected
procedure Execute; override;
public
//property Onkkk: Tkkk read FOnkkk write FOnkkk;
end;

implementation
uses csendformp;



procedure tlistsend.Execute;
var
i:integer;
begin

for i:=0 to 10 do
begin

if Assigned(csend.Onretucmd) then csend.Onretucmd(i);
sleep(1000);
end;
{ Place thread code here }
end;

end.

客户端调用showme方法会出错
procedure TTmysend.Initialize;
begin
inherited Initialize;
//csend.Onretucmd:=self.sss; 取消后运行正常 csend.Onretucmd事件本身是正常的.
FConnectionPoints := TConnectionPoints.Create(Self);

搞不明白出错在那里,请朋友指点指点.
 
都没人指点一下吗。怎么我提的问题根本上都是我自己花上N多无用功之后才能得到解决呢。我都好多贴都结不了,没人回复过呀,想把以前的那些废贴都结了都结不了呀。
 
[:(]DELPHI没落了?[:D]蹭分
 
我记得《开发指南》上有这样的例子的啊。(不是开发指南就是《深入COM编程》这本书)
当时我还照着书写了例子的呢。
你放了这么代码,没有人愿意去花时间仔细看的。只有你把问题的症状,你的目的说清楚,别人还是愿意一起讨论的。
 
例子仔细看过的。能实现事件。比如说COM里一个窗体里按键的事件能够反馈给调用端。
我想实现自定义的事件反馈给调用端,实现不了。
 
问题自己已解决.很常识的地方没有注意到而已.浪费我N多时间,怎么就没有高手来帮帮我呢.
 
问题自己已解决.很常识的地方没有注意到而已.浪费我N多时间,怎么就没有高手来帮帮我呢.
 

Similar threads

I
回复
0
查看
728
import
I
I
回复
0
查看
633
import
I
I
回复
0
查看
527
import
I
I
回复
0
查看
504
import
I
后退
顶部