这是一个从Dll中导出类的例子,运行时会出现一个“EConvertError” 错误信息 是“cannot assign a TFont to a TFont", 如果不从Dll导出类,就没有这种错误。 该例子包含一个Dll工程,两个单元和一个调用Dll的程序。源码如下:
//------- 从Dll导出类发生错误的情况 -------------//
1。Dll工程
library DllObj;
{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }
uses SysUtils, Classes, dllclass in 'dllclass.pas';
{$R *.res}
exports NewObject;
begin end.
---------------- 2。base 单元
unit base;
interface
uses Controls, ComCtrls, ExtCtrls, Menus;
type TDllNumber = class public procedure InsertMenu(ParentMenu: TMainMenu); virtual; abstract; procedure InsertCtrl(APanel: TPanel); virtual; abstract; end;
{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }