1
我創建了一個非常小的自動化對象(使用delphi 7)。 它可以工作,但我有問題將它註冊到運行的對象表中,以便我可以使用getActiveOleObject函數來檢索服務器的運行實例。 問題是Initialize和Destroy事件不會觸發。Delphi - 在ROT中註冊com服務器
編輯: 我剛剛注意到,初始化被激發,當我通過createOleObject在客戶端應用程序中創建應用程序。
EDIT2: 下載樣本PROJEKT here
這裏的源代碼:
unit mycomserver;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, server_TLB, StdVcl, dialogs;
type
Tmyserver = class(TAutoObject, Imyserver)
private
FROTCookie: Longint;
public
procedure Initialize; override;
destructor Destroy; override;
protected
procedure hello; safecall;
end;
implementation
uses ComServ;
procedure Tmyserver.Initialize;
begin
inherited;
//Register object in ROT
showmessage('Why the init event doesnt fire?');
OleCheck(RegisterActiveObject(Self, CLASS_myserver, ActiveObject_Weak, FROTCookie))
end;
destructor Tmyserver.Destroy;
begin
// unegister object in ROT
showmessage('And destroy event also doesnt fire...');
OleCheck(RevokeActiveObject(FROTCookie, nil));
inherited;
end;
procedure Tmyserver.hello;
begin
showmessage('hello its me the comserver');
end;
initialization
showmessage('com server init works...');
TAutoObjectFactory.Create(ComServer, Tmyserver, Class_myserver,
ciMultiInstance, tmApartment);
end.
看看它顯示代碼如何做到這一點。 http://www.blong.com/Conferences/IConUK2000/DelphiMoreAutomation/More%20Automation%20In%20Delphi.htm 您可能已有。 – 2010-07-06 21:57:04
是啊,這正是我所讀的... – ben 2010-07-07 05:12:41