代码如下
1. 类库unit
library ProductShow; //activex library
uses
ComServ,
ADODB,
DBEntity in 'DBEntity.pas',
Product in 'Product.pas',
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;{$R *.TLB}{$R *.RES}begin
end.2.接口unit
unit DBEntity_TLB;interface
type
IDBEntity = interface
['{79F4C40B-9774-4B3A-9768-31A05E8DA576}']
//function
procedure SetField(Index: integer; Value: Variant);
function GetField(Index: integer): Variant;
property Fields[Index: integer]: Variant read GetField;
end;
implementationend.3. 类unit (太长,只贴和接口有关的定义)
unit DBEntity;interfaceuses ADODB, Contnrs, SysUtils, ComObj, DBEntity_TLB;type
TDBEntity = class(TComObject, IDBEntity)
public
procedure SetField(Index: integer; Value: Variant); virtual;
function GetField(Index: integer): Variant;
end;以上完全可以编译通过,但是dll注册以后,发现注册表根本找不到需要的progID
上面的代码都是新建unit手工写的,delphi太复杂,不知道还需要什么步骤
1. 类库unit
library ProductShow; //activex library
uses
ComServ,
ADODB,
DBEntity in 'DBEntity.pas',
Product in 'Product.pas',
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;{$R *.TLB}{$R *.RES}begin
end.2.接口unit
unit DBEntity_TLB;interface
type
IDBEntity = interface
['{79F4C40B-9774-4B3A-9768-31A05E8DA576}']
//function
procedure SetField(Index: integer; Value: Variant);
function GetField(Index: integer): Variant;
property Fields[Index: integer]: Variant read GetField;
end;
implementationend.3. 类unit (太长,只贴和接口有关的定义)
unit DBEntity;interfaceuses ADODB, Contnrs, SysUtils, ComObj, DBEntity_TLB;type
TDBEntity = class(TComObject, IDBEntity)
public
procedure SetField(Index: integer; Value: Variant); virtual;
function GetField(Index: integer): Variant;
end;以上完全可以编译通过,但是dll注册以后,发现注册表根本找不到需要的progID
上面的代码都是新建unit手工写的,delphi太复杂,不知道还需要什么步骤
类unit中少贴了property
property Fields[Index:integer]: Variant read GetField;
File | New | Other... | ActiveX | ActiveX library 生成 Dll 的框架。
进程外服务器:
File | New | Application 就行了。然后添加 COM 对象。 File | New | Other... | ActiveX 中选择 COM Object (如果想生成自动化对象,选择 Automation Object),接着就可以利用 类型库编辑器(View | Type Library) 定义接口了。没必要还用手工定义。这些东西很多书上都讲了!
建议你用delphi的com向导,borland再不好相信也比这里95%的人手写出来的强。
我都没用过delphi的,帮人家做毕业设计而已。
没用过,不知道delphi多难用,
那么多的activex,我花了好久才算有点明白用哪个(其实还不是一回事?)
接口定义没错,类实现也调试过,libray的框架也是自动生成的,我只是想把他们合起来而已阿,——————真是累死了。
说的“类型库编辑器”我也用过,用这个倒是可以,
可是我不清楚他们之间的关系,
还有接口property Fields[Index: integer] 该怎么写?都没地方写参数的。
就算com向导多么方便,我还是希望弄清楚他们的关系
libray, class , interface, 怎么组合到一起
或者谁介绍下.idl(类型库编辑器导出来的)文件怎么用
没有实现IDISPATCH接口,自然在注册表里面找不到progID其实也用不着PROGID,直接知道CLASS的GUID和INTERFACE的GUID就可以调用了。
确实没有实现IDispatch接口
是放到网页上用的,不提供progID太过分了。
这么说只是没有实现IDispatch而已咯?
有什么类实现了IUnknown 、IDispatch接口的?
只要继承它们其中一个就行.
它们区别是前者是独立实现,后者是配合TAutoObjectFactory使用.
一般使用后者方便些.所谓注册,也是COM组件自己代码把注册信息写进注册表,所以,你不是使用FACTORY
已经实现的,就是自己写注册代码.
具体怎么写可以参照DELPHI自动生成的AUTO OBJECT代码.