就语句本身来看,没有语法的错误。我写了个简单的调用DLL的例子(DLL中包含窗体)DLL部分 --------library ShowForm;{ 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, Unit1 in 'Unit1.pas' {frmMain};{$R *.RES}procedure ShowModalForm; pascal; begin frmMain := TfrmMain.Create(nil); frmMain.ShowModal; frmMain.Free; frmMain := nil; end;exports ShowModalForm;begin end. PROJECT部分 ------------ unit PUnit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;procedure ShowModalForm; pascal; external 'ShowForm.dll';var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject); begin ShowModalForm; end;end.-------- 以上是大致内容。 没有出现提示地址错。你上面用的是Show过程,不是有模式的窗体,因为对象本身不能释放自己,所以,你需要在Project中有释放窗体的语句。
....
Form1.Free; //??当然有问题
--------library ShowForm;{ 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,
Unit1 in 'Unit1.pas' {frmMain};{$R *.RES}procedure ShowModalForm; pascal;
begin
frmMain := TfrmMain.Create(nil);
frmMain.ShowModal;
frmMain.Free;
frmMain := nil;
end;exports
ShowModalForm;begin
end.
PROJECT部分
------------
unit PUnit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;procedure ShowModalForm; pascal; external 'ShowForm.dll';var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
ShowModalForm;
end;end.--------
以上是大致内容。
没有出现提示地址错。你上面用的是Show过程,不是有模式的窗体,因为对象本身不能释放自己,所以,你需要在Project中有释放窗体的语句。
创建的窗体我不希望都模态显示呀!我也遇到同样的情况!
然后可以通过得到的窗体对象地址释放。传回给Project
--------------
function ShowModalForm: Longint; pascal;
begin
frmMain := TfrmMain.Create(nil);
if frmMain <> nil then
Result := Longint(frmMain) else
Result := 0;
end;
--------------
Project 就得到了创建好了的窗体实例了,你也就可以在Porject 中控制窗体了(比如Show)。释放窗体
--------------
假设你将得到的窗体实例放在DLLForm: Longint中。if DLLForm <> 0 then TForm(DLLForm).Free;将窗体进行释放。