我想设计Delphi插件框架.有三个选项:
1.DLL
2. BPL
3. COM接口
每个选项都有一些缺点.
DLL - 带有MDI apllication的Promblem,来自插件的表单不能嵌入到主机exe-mdi应用程序中.
BPL - 必须使用相同版本的Delphi编译每个*.bpl插件和*.exe主机应用程序.
COM - 接口{xxx-xx-xxx-xx}必须在系统中注册,(regsvr)因此插件框架不能移植!
我上面写的一切都是真的吗?如果没有,请纠正我,还是有其他可能性?
谢谢
我试图从dll函数返回我自己的对象(从TCollection派生).我使用FastMemoryManager,但没有成功......所以我试图返回一些对象的动态数组.
当前在dll函数中的数组的长度.它工作得很好,但是没有释放分配的内存.
(我用Windows tarsk经理测量).是否有可能如何释放动态数组?调用dll函数的过程在线程中,最后我有以下内容:
for i := 0 to length(MyObjectArray) - 1 do begin
if MyObjectArray[i] <> nil then
MyObjectArray[i].Free;
end;
Setlength(MyObjectArray, 0);
MyObjectArray := nil;
Run Code Online (Sandbox Code Playgroud)
如果我使用而不是Setlength(MyObjectArray,0)和MyObjectArray:= nil,则
引发FreeAndNil(MyObjectArray) 异常.
有什么建议吗?
这个问题从这个arised 一个.
问题是:创建非可视组件,可以从系统中保存许多回调命令.用户可以在IDE中定义无限数量的回调.回调将在TCollection中定义为TCollectionItem.
这是一种非常好的模式,但有一些缺点.(后面会说)因此我想知道,如果可以做得更好;-)
这是一个主要组件,用户可以通过CommandsTable集合在IDE中定义无限数量的回调函数
TMainComp = class(TComponent)
private
CallbacksArray: array [0..x] of pointer;
procedure BuildCallbacksArray;
public
procedure Start;
published
property CommandsTable: TCommandCollection read FCommandsTable write SetCommandsTable;
end;
Run Code Online (Sandbox Code Playgroud)
每个集合项都如下所示,InternalCommandFunction是回调函数,它是从系统调用的.(Stdcall呼叫公约)
TCommandCollectionItem = class(TCollectionItem)
public
function InternalCommandFunction(ASomeNotUsefullPointer:pointer; ASomeInteger: integer): Word; stdcall;
published
property OnEventCommand: TComandFunc read FOnEventCommand write FOnEventCommand;
end;
Run Code Online (Sandbox Code Playgroud)
TComandFunc = function(AParam1: integer; AParam2: integer): Word of Object;
Run Code Online (Sandbox Code Playgroud)
这是一个实现.整个过程可以通过"开始"程序开始
procedure TMainComp.Start;
begin
// fill CallBackPointers array with pointers to CallbackFunction
BuildCallbacksArray;
// function AddThread is from EXTERNAL dll. This function …Run Code Online (Sandbox Code Playgroud)