简单DLL问题(50分)

  • 主题发起人 主题发起人 ml.guo
  • 开始时间 开始时间
M

ml.guo

Unregistered / Unconfirmed
GUEST, unregistred user!
Project1.dll,建立了一过程showform,显示一窗口fm1,
project2.exe调用project1.dll的showform。
问题:运行project2.exe时,总是先显示project1.dll的窗口fm1,关闭fm1后才弹出project2.exe有主窗口。
但是project2.exe中是要点击bitbtn按键才调用showform的。为什么??
---project1.dll
library Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {fm};
{$R *.res}
exports
showform;
begin
Application.Initialize;
Application.CreateForm(Tfm, fm);
Application.Run;
end.
---unit1.pas
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;

type
Tfm = class(TForm)
Edit1: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
private
{ Private declarations }
public
{ Public declarations }
end;

var
fm: Tfm;

procedure showform;stdcall;

implementation

{$R *.dfm}

procedure showform;
begin
fm:=tfm.Create(application);
try
fm.ShowModal;
finally
fm.Free;
end;
end;
end.
--------------------------------
project2.exe

unit2.pas
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm2 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
procedure showform;stdcall;external 'project1.dll';

implementation
{$R *.dfm}
procedure TForm2.BitBtn1Click(Sender: TObject);
begin
showform;
end;
end.


 
dll的Tfm,在Tfm的属性那里设置 Visible=false
dll中不要下面的代码:
Application.Initialize;
Application.CreateForm(Tfm, fm);
Application.Run;
改成
fm:=Tfm.Create(nil); 一行
 
接受答案了.
 

Similar threads

I
回复
0
查看
650
import
I
I
回复
0
查看
515
import
I
I
回复
0
查看
633
import
I
I
回复
0
查看
709
import
I
I
回复
0
查看
778
import
I
后退
顶部