在dll中delphi中封装窗体(实例)
2009-10-10 13:54
381 查看
dll工程
library FormDLL;
{ 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,
Forms,
DLLForm in 'DLLForm.pas' {frmDLL},
dllFrom2 in 'dllFrom2.pas' {Form2};
{$R *.res}
exports
SynAPP,ShowForm;
begin
end.
//dll单元文件一
unit DLLForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,iniFiles;
type
TfrmDLL = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmDLL: TfrmDLL;
procedure SynAPP(App:THandle);stdcall;
procedure ShowForm;stdcall;
implementation
uses Math,dllFrom2;
{$R *.dfm}
procedure SynAPP(App:THandle );stdcall;
begin
Application.Handle := App;
end;
procedure ShowForm;stdcall;
begin
try
frmDLL := TfrmDLL.Create (Application);
try
if frmDLL.ShowModal = idOk then
begin
try
Form2 := TForm2.Create(Application);
Form2.ShowModal;
finally
FreeAndnil(Form2);
end;
end;
finally
FreeAndNil(frmDLL);
end;
except
on E: Exception do
MessageDlg ('Error in DLLForm: ' +
E.Message, mtError, [mbOK], 0);
end;
end;
procedure TfrmDLL.Button1Click(Sender: TObject);
begin
self.ModalResult := idOk;
end;
end.
dll单元文件二
unit dllFrom2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,iniFiles, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var
sMsg : string;
begin
with TiniFile.Create(ExtractFilePath(paramstr(0)) + 'config.ini') do
begin
try
sMsg := ReadString('hello','abc','NO');
ShowMessage(sMsg);
finally
free;
end;
end;
end;
end.
测试工程
program test;
uses
Forms,
testDLLForm in 'testDLLForm.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
//单元文件
unit testDLLForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,iniFiles;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure SynAPP(App:THandle);stdcall;external 'FormDLL.dll'; //这里的
procedure ShowForm;stdcall;external 'FormDLL.dll';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
SynAPP(Application.Handle);
ShowForm ;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
sMsg : string;
begin
with TiniFile.Create(ExtractFilePath(paramstr(0)) + 'config.ini') do
begin
try
sMsg := ReadString('hello','abc','NO');
ShowMessage(sMsg);
finally
free;
end;
end;
end;
end.
library FormDLL;
{ 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,
Forms,
DLLForm in 'DLLForm.pas' {frmDLL},
dllFrom2 in 'dllFrom2.pas' {Form2};
{$R *.res}
exports
SynAPP,ShowForm;
begin
end.
//dll单元文件一
unit DLLForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,iniFiles;
type
TfrmDLL = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmDLL: TfrmDLL;
procedure SynAPP(App:THandle);stdcall;
procedure ShowForm;stdcall;
implementation
uses Math,dllFrom2;
{$R *.dfm}
procedure SynAPP(App:THandle );stdcall;
begin
Application.Handle := App;
end;
procedure ShowForm;stdcall;
begin
try
frmDLL := TfrmDLL.Create (Application);
try
if frmDLL.ShowModal = idOk then
begin
try
Form2 := TForm2.Create(Application);
Form2.ShowModal;
finally
FreeAndnil(Form2);
end;
end;
finally
FreeAndNil(frmDLL);
end;
except
on E: Exception do
MessageDlg ('Error in DLLForm: ' +
E.Message, mtError, [mbOK], 0);
end;
end;
procedure TfrmDLL.Button1Click(Sender: TObject);
begin
self.ModalResult := idOk;
end;
end.
dll单元文件二
unit dllFrom2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,iniFiles, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var
sMsg : string;
begin
with TiniFile.Create(ExtractFilePath(paramstr(0)) + 'config.ini') do
begin
try
sMsg := ReadString('hello','abc','NO');
ShowMessage(sMsg);
finally
free;
end;
end;
end;
end.
测试工程
program test;
uses
Forms,
testDLLForm in 'testDLLForm.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
//单元文件
unit testDLLForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,iniFiles;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure SynAPP(App:THandle);stdcall;external 'FormDLL.dll'; //这里的
procedure ShowForm;stdcall;external 'FormDLL.dll';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
SynAPP(Application.Handle);
ShowForm ;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
sMsg : string;
begin
with TiniFile.Create(ExtractFilePath(paramstr(0)) + 'config.ini') do
begin
try
sMsg := ReadString('hello','abc','NO');
ShowMessage(sMsg);
finally
free;
end;
end;
end;
end.
相关文章推荐
- 在dll中delphi中封装窗体(实例)
- 在dll中delphi中封装窗体(实例)
- Delphi 创建封装窗体的 DLL 实例
- delphi的DLL封装MDI子窗体
- Delphi封装Mdi窗体到Dll并使用插件管理,tabControl制作多页面
- Delphi dll窗体封装
- DELPHI 在DLL中封装的VCL窗体Tab键响应的问题
- 用DELPHI创建DLL文件,封装窗体的实现方法实例
- 在dll中delphi中封装窗体
- Delphi dll窗体封装
- [轉]c#简单调用DELPHI DLL封装窗体
- Delphi 将窗体封装到DLL(中将EXE转换为DLL)-1
- delphi dll 实例 与 dll窗体实例
- Delphi 封装窗体封装DLL
- [整理]c#简单调用DELPHI DLL封装窗体
- Delphi经典实例8------自动隐藏窗体
- 解决Delphi开发DLL中窗体按钮显示状态不刷新问题.
- delphi dll实例代码 持续影响
- VC++中把窗体封装到dll中并调用
- [笔记]Delphi 2007写DLL供VC调用实例