本人试图将程序模块化,只要一个主界面,其它子窗体都封装在不同的DLL里,但是我没有做过不知道怎样写一个带窗体的dll,并在主窗口去调用这个dll。所以希望高手们提供一个完整的实例学习一下,谢谢
mailaddress: [email protected]
mailaddress: [email protected]
解决方案 »
- 急求各位高人msscript.ocx使用问题
- 关于皮肤问题?
- 关于PDF文件
- synedit老版本中的TSynSearchOptions在 最新的版本中是什么类型?
- 请问如何实践把数据库中NUMERIC类型的数据转换为FLOAT类型??在线等。。。
- 为什么打印机没连好时程序就报错
- 各位高手大家好:我有个问题就是数据库的内容相同如何读取,请看具体内容
- Treeview.savetofile保存时可以加入除text外的其他信息吗?
- 刚学DELPHI,一个菜鸟的问题。
- 请问那里有的delphi的中文补丁??
- 用image1.Canvas 绘制完图形后,如何清除?因为我要重新画另一各图形。
- 请看,这么长的时间了还不结贴?请版主严格控制此类贴!!!
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' {Form1};{$R *.RES}function Returnstr:string;stdcall;
begin
with TForm1.Create(nil) do
try
showmodal;
Result := trim(edit1.text);
finally
free;
end;
end;exports
Returnstr;begin
end.
这是dll的代码。
procedure TForm1.Button1Click(Sender: TObject);
var
DllHandle : THandle=0;
Rd : function : String; stdcall;
begin
DllHandle := LoadLibrary('mydll.dll');
if DllHandle > 0 then
@Rd := GetProcAddress(DllHandle,'ShowMainForm')
else
begin
DllHandle := 0;
@Rd := nil;
end; if (DllHandle > 0) and (@Rd <> nil) then
edit1.text := Rd
else
edit1.text := '';
end;
这是调用的代码。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
ApplicationName: String;
procedure LoadForm(Handle: THandle; AppName: ShortString); export;implementation{$R *.dfm}
procedure LoadForm(Handle: THandle; AppName: ShortString);
begin
Application.Handle := Handle;
ApplicationName := AppName;
Form1 := TForm1.Create(Application);
try
Form1.ShowModal;
finally
Form1.Free;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
self.close;
end;end.
//Dll代码
library usedll;uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}
exports
LoadForm index 1;
beginend.//建立一个工程调用DLL
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;
procedure LoadForm; external 'usedll.dll' index 1;
implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
begin
LoadForm;
end;end.
Project Project2.exe raised exception class EOSError with message 'System Error.Code:1400.无效的窗口句柄。',Process stopped.Use Step or Run to continue.只要我有收获一定给分。