Delphi COM Programming Study Note

in Theory:
 MyIntf := TMyIntf.create(10);
 MyIntf.AddRef;
 MyIntf.DoSth;
 MyIntf.Release;

in delphi:
 MyIntf := TMyIntf.create(10);
 MyIntf.DoSth;
 //do not call MyIntf.Free

---------
All In-Process COM Server export 4 functions:
DllRegisterServer:
 call by IDE' menu item "Run" -> "Register ActiveX Server" or
 Window command "RegSrv32.exe <Server Name>"
DllUnRegisterServer: reverse process of DllRegisterServer
 call by IDE' menu item "Run" -> "UnRegister ActiveX Server" or
 Window command "RegSrv32.exe -u <Server Name>"
DllGetClassObject: get the class factory
DllCanUnloadNow:

===============================================
Create In-Process COM Server DLL (A Project)
----------------
"File" -> "New" -> "ActiveX" -> "Activex Library" Item

Create COM Object (A COM Class)
----------------
"File" -> "New" -> "ActiveX" -> "COM Object" Item

Register(if you add dll in dcomcnfg.exe explorer, then you add a DCOM)
----------------
"File" -> "Run" -> "Register ActiveX Server" or
 Window command "RegSrv32.exe <Server Name>"

Create Client Application (uses the COM unit directly!!! sometimes this is unapplicable)
----------------
include COM object interface file, and you can create com object

===========================================
Type Library (need not uses COM unit directly) .TLB (a replacement tool for IDL)
----------------
if you add Type Library support in COM wizard, you inherited from TTypedComObject instead of TComObject

out-of-process need marshaling (in-process need not)
----------------

===============================================
two method to create variant array: VarArrayCreate(more flexible) and VarArrayOf
--------------------------------
define an variant array with size 10 and type integer: VarArrayCreate([1, 10], varInteger);
define mix type variant array in compile time: VarArrayOf(["John", 0, "Manager", 30000]);//seems like record


====================================
Early Binding
====================================
var
 MyIntf: IMyIntf;
begin
 MyIntf := IMyIntf.create(10);
 MyIntf.DoSomething;

====================================
Late Binding (Automation)
====================================
Get Type Library Information (IDispatch), used for Late Binding
----------------
var
 v: Variant;
  s: WideString;
begin
 //create a ActiveX Library(auto_svr1.dpr), add a automation object (AutoHello), you get a automation server
 v := CreateOleObject('auto_svr1.AutoHello');
 v.Add(87, s);
 ShowMessage(s);


====================================
DCOM require out-of-process automation server

====================================
Import type library (Early Binding ??) 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值