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 ??)