com问题,研究过com前辈请指点指点。TLB文件中不明白!!所有留言给意见者皆有分!! ( 积分: 200 )

  • 主题发起人 主题发起人 zhousi
  • 开始时间 开始时间
Z

zhousi

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Project1_TLB;

interface

uses Windows, ActiveX, Classes, Graphics, Midas, StdVCL, Variants;

const

Project1MajorVersion = 1;
Project1MinorVersion = 0;

LIBID_Project1: TGUID = '{5EE3CDF8-B351-4DB3-BA78-1F14AA78B940}';

IID_Itest: TGUID = '{1BD9A3DF-C462-4DC9-953C-21835631EAB0}';
CLASS_test: TGUID = '{0C34233D-49BA-42FD-AABA-F1A46F19473F}'; //类工厂的guid
type

Itest = interface;
ItestDisp = dispinterface;

test = Itest;

Itest = interface(IAppServer)
['{1BD9A3DF-C462-4DC9-953C-21835631EAB0}']
procedure ddf(aa: Integer); safecall;
end;

ItestDisp = dispinterface
['{1BD9A3DF-C462-4DC9-953C-21835631EAB0}']
procedure ddf(aa: Integer); dispid 1;
function AS_ApplyUpdates(const ProviderName: WideString; Delta: OleVariant; MaxErrors: Integer;
out ErrorCount: Integer; var OwnerData: OleVariant): OleVariant; dispid 20000000;
function AS_GetRecords(const ProviderName: WideString; Count: Integer; out RecsOut: Integer;
Options: Integer; const CommandText: WideString; var Params: OleVariant;
var OwnerData: OleVariant): OleVariant; dispid 20000001;
function AS_DataRequest(const ProviderName: WideString; Data: OleVariant): OleVariant; dispid 20000002;
function AS_GetProviderNames: OleVariant; dispid 20000003;
function AS_GetParams(const ProviderName: WideString; var OwnerData: OleVariant): OleVariant; dispid 20000004;
function AS_RowRequest(const ProviderName: WideString; Row: OleVariant; RequestType: Integer;
var OwnerData: OleVariant): OleVariant; dispid 20000005;
procedure AS_Execute(const ProviderName: WideString; const CommandText: WideString;
var Params: OleVariant; var OwnerData: OleVariant); dispid 20000006;
end;

Cotest = class
class function Create: Itest;
class function CreateRemote(const MachineName: string): Itest;
end;

implementation

uses ComObj;

class function Cotest.Create: Itest;
begin
Result := CreateComObject(CLASS_test) as Itest;
end;

class function Cotest.CreateRemote(const MachineName: string): Itest;
begin
Result := CreateRemoteComObject(MachineName, CLASS_test) as Itest;
end;

end.


1。Project1MajorVersion,Project1MinorVersion 不知道做什么用的一直不明白。
2。guid使用
LIBID_Project1: TGUID = '{5EE3CDF8-B351-4DB3-BA78-1F14AA78B940}';
IID_Itest: TGUID = '{1BD9A3DF-C462-4DC9-953C-21835631EAB0}';
不知道在什么地方用
CLASS_test 应该是类工厂的guid
3。test = Itest;
定义test是Itest接口类型的,好像没用到。不知道生成出来做什么
4。ItestDisp = dispinterface
dispinterface不知道做什么用,每增加个方法,Itest和ItestDisp都要添加。
5。就是Cotest类。。为什么还要在com里有这个类。调用CreateComObject和CreateRemoteComObject
这两个方法应该在客户端或外界使用嘛。在com里使用到了?
 
unit Project1_TLB;

interface

uses Windows, ActiveX, Classes, Graphics, Midas, StdVCL, Variants;

const

Project1MajorVersion = 1;
Project1MinorVersion = 0;

LIBID_Project1: TGUID = '{5EE3CDF8-B351-4DB3-BA78-1F14AA78B940}';

IID_Itest: TGUID = '{1BD9A3DF-C462-4DC9-953C-21835631EAB0}';
CLASS_test: TGUID = '{0C34233D-49BA-42FD-AABA-F1A46F19473F}'; //类工厂的guid
type

Itest = interface;
ItestDisp = dispinterface;

test = Itest;

Itest = interface(IAppServer)
['{1BD9A3DF-C462-4DC9-953C-21835631EAB0}']
procedure ddf(aa: Integer); safecall;
end;

ItestDisp = dispinterface
['{1BD9A3DF-C462-4DC9-953C-21835631EAB0}']
procedure ddf(aa: Integer); dispid 1;
function AS_ApplyUpdates(const ProviderName: WideString; Delta: OleVariant; MaxErrors: Integer;
out ErrorCount: Integer; var OwnerData: OleVariant): OleVariant; dispid 20000000;
function AS_GetRecords(const ProviderName: WideString; Count: Integer; out RecsOut: Integer;
Options: Integer; const CommandText: WideString; var Params: OleVariant;
var OwnerData: OleVariant): OleVariant; dispid 20000001;
function AS_DataRequest(const ProviderName: WideString; Data: OleVariant): OleVariant; dispid 20000002;
function AS_GetProviderNames: OleVariant; dispid 20000003;
function AS_GetParams(const ProviderName: WideString; var OwnerData: OleVariant): OleVariant; dispid 20000004;
function AS_RowRequest(const ProviderName: WideString; Row: OleVariant; RequestType: Integer;
var OwnerData: OleVariant): OleVariant; dispid 20000005;
procedure AS_Execute(const ProviderName: WideString; const CommandText: WideString;
var Params: OleVariant; var OwnerData: OleVariant); dispid 20000006;
end;

Cotest = class
class function Create: Itest;
class function CreateRemote(const MachineName: string): Itest;
end;

implementation

uses ComObj;

class function Cotest.Create: Itest;
begin
Result := CreateComObject(CLASS_test) as Itest;
end;

class function Cotest.CreateRemote(const MachineName: string): Itest;
begin
Result := CreateRemoteComObject(MachineName, CLASS_test) as Itest;
end;

end.


1。Project1MajorVersion,Project1MinorVersion 不知道做什么用的一直不明白。
2。guid使用
LIBID_Project1: TGUID = '{5EE3CDF8-B351-4DB3-BA78-1F14AA78B940}';
IID_Itest: TGUID = '{1BD9A3DF-C462-4DC9-953C-21835631EAB0}';
不知道在什么地方用
CLASS_test 应该是类工厂的guid
3。test = Itest;
定义test是Itest接口类型的,好像没用到。不知道生成出来做什么
4。ItestDisp = dispinterface
dispinterface不知道做什么用,每增加个方法,Itest和ItestDisp都要添加。
5。就是Cotest类。。为什么还要在com里有这个类。调用CreateComObject和CreateRemoteComObject
这两个方法应该在客户端或外界使用嘛。在com里使用到了?
 
1:是工程版本号
2:请高手回答
3:定义一个ITest的别名,既test可以表示ITest
4:这是分派机制,所有调用函数都是通过分派机制完成的
5:生成CoXXX类是为了方便VCL直接使用,Delphi开发时更加方便。可以直接在delphi里面写
XXX := TCoXXX.Create;
就可得到接口。使得对接口的创建和普通类的创建风格一致。

如有不对的地方,请高手指教。
 
1、版本号,平常很少用到
2、客户端发起连接时会用到GUID(主要是CLASS_test 的GUID)
3、肯定用到了
你看你的DataModule就是从它继承的
 
CLASS_test,注意,他在CoTest类中被用到了
 
谢谢
zqw0117,xianguo

2。guid使用
LIBID_Project1: TGUID = '{5EE3CDF8-B351-4DB3-BA78-1F14AA78B940}';
IID_Itest: TGUID = '{1BD9A3DF-C462-4DC9-953C-21835631EAB0}';
不知道在什么地方用
CLASS_test 应该是类工厂的guid

4。ItestDisp = dispinterface
dispinterface不知道做什么用,每增加个方法,Itest和ItestDisp都要添加。

基本明白,4。只是定义个接口,但并没用到,可以自己试试,呵呵。直接删除我想应该也没什么问题。
2。guid我再试试,可能有一个没用到,一个是工厂类guid,一个可能是dll注册的guid。或真正实例的guid。偶再去翻翻资料。
过会散分。。。
 
多人接受答案了。
 
后退
顶部