关于接口, 插件的问题!(如何用Delphi的接口实现插件?)
以下是我的办法, 我觉得不好, 请大家给个好的意见!
[dll]
uses
SysUtils,
Classes,
Dialogs,
Plug in 'Plug.pas';
type
TDocument = class(TInterfacedObject, IDocument)
private
FStrings: string;
public
procedure Created;
procedure Destroyed;
procedure CreateString(str: string);
function ResultString: string;
end;
{$R *.res}
var
Document: IDocument;
{ TDocument }
procedure TDocument.Created;
begin
ShowMessage('Document is created');
end;
procedure TDocument.CreateString(str: string);
begin
FStrings := str + 'one';
end;
procedure TDocument.Destroyed;
begin
ShowMessage('Document is destroyed');
end;
function TDocument.ResultString: string;
begin
Result := FStrings;
end;
function CreateClass(): IDocument; stdcall;
begin
Document := TDocument.Create();
Result := Document;
end;
exports
CreateClass name 'CreateClass';
begin
end.
[定义的接口]
unit Plug;
interface
uses Windows;
type
IDocument = interface
procedure Created;
procedure Destroyed;
procedure CreateString(str: string);
function ResultString: string;
end;
有几个问题, 我除了在dll里放一个CreateClass方法, 来导出IDocument外, 实在想不出其它方法了, 大家可以帮我想想还有什么别的方法么? 还有一个就是, 在主程序里FreeLibrary的时候, 会出问题, 我搜过以前的一个贴子说要导出接口, 不知道他是怎么导的, 没有源码, 谁知道这个问题, 请回答, 谢谢了!