紧急求助(200分)

  • 主题发起人 主题发起人 zhaowei7804
  • 开始时间 开始时间
Z

zhaowei7804

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样用delphi来实现封装的dll能动态调用窗口(在dll中显示窗口)

最好有实际例程
 
DLL的接口函数里写
form1 := TForm1.Create(Application);
form1.Show;

调用就行了,不过我不会把它做成MDI子窗体。有会的加我一下。
QQ 26761119
 
DLL工程文件:
library FormDLL;
uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas' {Form1};

exports
ShowMyForm Name 'ShowMyForm';

{$R *.res}

begin
end.

DLL窗体文件:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
procedure ShowMyForm; export;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;

procedure ShowMyForm;
begin
Form1:= TForm1.Create(Application);
Form1.ShowModal;
end;

end.

调用方法:
implementation
procedure ShowMyForm; external 'FormDLL.dll' Name 'ShowMyForm';

{$R *.dfm}

procedure TDLLTEST.Button1Click(Sender: TObject);
begin
ShowMyForm;
end;
 
就这么简单呀没什么的楼上的兄弟都这样了还不明白就不要用D了,用VB吧。
 
给一个例子,请看下面代码:
library AboutDll;

uses
Forms,
UnitAbout in 'UnitAbout.pas' {Frm_About};

exports
ShowAboutFrm;
begin
end.

Dll窗体代码:

unit UnitAbout;

interface

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

type
TSimpleVersion = record
dwProductVersionMS: DWORD;
dwProductVersionLS: DWORD;
end;
TUpdate = record { Structure of update information }
Name:String[63];
Version:TSimpleVersion;
Date:TDate;
URL:ShortString;
end;

TFrm_About = class(TForm)
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Bevel1: TBevel;
Label6: TLabel;
Button1: TButton;
Button2: TButton;
Label7: TLabel;
FlatEdit1: TFlatEdit;
FlatEdit2: TFlatEdit;
Label8: TLabel;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

procedure ShowAboutFrm(AHandle: THandle; ACaption: string; AName: string); stdcall; //显示关于窗口

implementation

{$R *.dfm}

procedure ShowAboutFrm(AHandle: THandle; ACaption: string; AName: string);
var
Frm_About: TFrm_About;
begin
Application.Handle := AHandle;
Frm_About := TFrm_About.Create(Application);
with Frm_About do
try
Caption := ACaption;
Label1.Caption := AName;
ShowModal;
finally
Free;
end;
end;

procedure TFrm_About.Button2Click(Sender: TObject);
begin
ShowMessage('正在开发中');
end;

end.

调用该Dll例程

unit Unit1;

interface

uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;

type
TShowAbout = procedure(AHandle: THandle; ACaption: string; AName: string); StdCall;

EDLLLoadError = class(Exception);


TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
LibHandle: THandle;
ShowAbout: TShowAbout;
begin
LibHandle := LoadLibrary('Aboutdll.DLL');
try
if LibHandle = 0 then
raise EDLLLoadError.Create('不能装载动态链接库,请确认动态链接库的存在!');
@ShowAbout := GetProcAddress(LibHandle, 'ShowAboutFrm');
if not (@ShowAbout = nil) then
ShowAbout(Form1.Handle, 'About...','飘摇客通讯录')
else
RaiseLastWin32Error;
finally
FreeLibrary(LibHandle); // Unload the DLL.
end;
end;

end.
 
看这里
http://www.delphibbs.com/delphibbs/dispq.asp?lid=534762

在动态连接库中的MDI子窗体:

library MDIDll;
var
SaveDLLApp:TApplication;

procedure ShowMDIChildForm(MainApp:TApplication);
var
Child:TMDIForm;
begin
if not Assigned(SaveDllApp) then
begin
SaveDllApp:=Application;
Application:=MainApp;
end;
Child:=TMDIForm.Create(Application.MainForm);
Child.Show;
end;

procedure MyLibraryProc(Reason:integer);
begin
if Reason=DLL_PROCESS_DETACH then
if Assinged(SaveDllApp) then
Application:=SaveDllApp;
end;

export ShowMDIChildForm;

begin
DllProc:=@MyLibraryProc;
end.

在调用dll的应用中,用下述方法生MDI窗体;
procedure Form1.Button1Click(Sender:Tobject);
begin
ShowMDIChildForm(Application);
end;
 
我需要的是动态调用的方法,诸位老兄给出的是动态调用的方法。
静态调用的我已经做完了。

我十分的感谢诸位高手的指点,我想动态的调用。
分数我已经向各位真心帮助我的兄弟发放了,请查收。

 
诸位老兄请注意,我要的是动态调用的实例而不是静态调用的实例。
 
后退
顶部