在Dll中重用两个窗体
在Dll中重用两个窗体,用其中一个窗体上的buttonclick事件来显示另一个窗体为什么会出错!代码如下:
.........................................主程序,用来调用DLL
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Ttextdll = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
textdll: Ttextdll;
implementation
procedure ShowAboutDlg;stdcall;far;external'Project1.dll';//声明调用
{$R *.dfm}
procedure Ttextdll.Button1Click(Sender: TObject);
begin
ShowAboutDlg;//调用的过程
end;
.....................................................Dll的单元1,有三个button,为什么第三个会错
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Image1: TImage;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure ShowAboutDlg;export;//输出
implementation
uses Unit2;
{$R *.dfm}
procedure ShowAboutDlg;//函数
begin
Form1:=TForm1.Create(Application);
Try
Form1.ShowModal;
finally
Form1.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
close;//没有报错
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage('howoldareyou');//没有报错,正常使用
end;
procedure TForm1.Button3Click(Sender: TObject);export;
begin
form2.show;//这里出错,为什么form2出不来呢,且还报Access violation at address 003A1ADD in moudoue 'project1.dll'
end;
end.
.................................................DLL 的单元2。这里窗体什么也没做,只是让能够显示
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm2 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
end.
.......................................................................dll的工程单元
library Project1;
uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in '..\..\..\..\Program Files\Borland\Delphi7\Projects\Unit2.pas' {Form2};
{$R *.res}
exports
ShowAboutDlg;//向调用程序输出过程
begin
end.