X
xport
Unregistered / Unconfirmed
GUEST, unregistred user!
昨天看了Delphi帮助文档中说的CoClass的资料,有点费解,请问CoClass到底是COM对象的类工厂呢?还是对COM所定义接口的实现类.
COM object 与 CoClass间的关系是什么样的?
谢谢.
_________________________________________________________________________
A COM object is an instance of a CoClass, which is a class that implements one or more COM interfaces. The COM object provides the services as defined by its interfaces.
CoClasses are instantiated by a special type of object called a class factory. Whenever an object's services are requested by a client, a class factory creates an object instance for that particular client. Typically, if another client requests the object's services, the class factory creates another object instance to service the second client. (Clients can also bind to running COM objects that register themselves to support it.)
A CoClass must have a class factory and a class identifier (CLSID) so that it can be instantiated externally, that is, from another module. Using these unique identifiers for CoClasses means that they can be updated whenever new interfaces are implemented in their class. A new interface can modify or add methods without affecting older versions, which is a common problem when using DLLs.
Delphi wizards take care of assigning class identifiers and of implementing and instantiating class factories.
还有,我看了在delphi中对COM的定义,有2个.pas文件,一个是TLB Wrapper,里面只有对CoClass,interface,CLSID等的定义,另一个是COM 中,interface的具体实现。
比如:对于Sample02.tlb,有一个wrapper文件:Sample02_TLB.pas,内容有TClass01的CoClass的实现:
CoTClass01 = class
class function Create: ITClass01;
class function CreateRemote(const MachineName: string): ITClass01;
end;
class function CoTClass01.Create: ITClass01;
begin
Result := CreateComObject(CLASS_TClass01) as ITClass01;
end;
class function CoTClass01.CreateRemote(const MachineName: string): ITClass01;
begin
Result := CreateRemoteComObject(MachineName, CLASS_TClass01) as ITClass01;
end;
还有一个文件:TClass01Unit.pas是对TClass01的interface的实现:
TTClass01 = class(TAutoObject, ITClass01)
protected
function Method1: OleVariant; safecall;
end;
function TTClass01.Method1: OleVariant;
begin
Result := 'Hello Word';
end;
COM object 与 CoClass间的关系是什么样的?
谢谢.
_________________________________________________________________________
A COM object is an instance of a CoClass, which is a class that implements one or more COM interfaces. The COM object provides the services as defined by its interfaces.
CoClasses are instantiated by a special type of object called a class factory. Whenever an object's services are requested by a client, a class factory creates an object instance for that particular client. Typically, if another client requests the object's services, the class factory creates another object instance to service the second client. (Clients can also bind to running COM objects that register themselves to support it.)
A CoClass must have a class factory and a class identifier (CLSID) so that it can be instantiated externally, that is, from another module. Using these unique identifiers for CoClasses means that they can be updated whenever new interfaces are implemented in their class. A new interface can modify or add methods without affecting older versions, which is a common problem when using DLLs.
Delphi wizards take care of assigning class identifiers and of implementing and instantiating class factories.
还有,我看了在delphi中对COM的定义,有2个.pas文件,一个是TLB Wrapper,里面只有对CoClass,interface,CLSID等的定义,另一个是COM 中,interface的具体实现。
比如:对于Sample02.tlb,有一个wrapper文件:Sample02_TLB.pas,内容有TClass01的CoClass的实现:
CoTClass01 = class
class function Create: ITClass01;
class function CreateRemote(const MachineName: string): ITClass01;
end;
class function CoTClass01.Create: ITClass01;
begin
Result := CreateComObject(CLASS_TClass01) as ITClass01;
end;
class function CoTClass01.CreateRemote(const MachineName: string): ITClass01;
begin
Result := CreateRemoteComObject(MachineName, CLASS_TClass01) as ITClass01;
end;
还有一个文件:TClass01Unit.pas是对TClass01的interface的实现:
TTClass01 = class(TAutoObject, ITClass01)
protected
function Method1: OleVariant; safecall;
end;
function TTClass01.Method1: OleVariant;
begin
Result := 'Hello Word';
end;