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);
搞不明白出错在那里,请朋友指点指点.
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);
搞不明白出错在那里,请朋友指点指点.