当前位置:主页>仓库管理软件> 列表

使用DLL文件中封装的窗口 找p3工程管理软件

记账软件版1楼: 打开Delphi新建一个DLL工程,保存为usedll,生成代码如下:
library usedll;
uses
SysUtils,
Classes,
Form_Unit in ''Form_Unit.pas'' {Form1};
{$R *.res}
exports
LoadForm index 1;
begin
end.
新建一个窗体,添加一个Label和Button,生成代码如下:
unit Form_Unit;
interface
uses
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中封装的窗口,新建一个工程,添加一个Button,代码如下:
unit Use_Unit;

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 LoadForm; external ''usedll.dll'' index 1;
implementation

{$R *.dfm}

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

end.
======================================================
以上代码网上有,但我在D7中编译后,运行时出错:
raise EOSError错误,错在哪里了?
网上的牛人还在到处引用这文章呢,害我等菜鸟.

2楼: procedure LoadForm(Handle: THandle; AppName: pchar); export;
implementation
{$R *.dfm}
procedure LoadForm(Handle: THandle; AppName: pchar); 如p3工程管理软件

3楼: 不是这个问题吧

4楼: var
Form1: TForm1;
procedure LoadForm; external ''usedll.dll'' index 1;

这个声明和你dll里导出涵数的声明不一致

5楼: EOSError is raised by the RaiseLastOSError procedure if the operating system returns an error code. The exception dialog contains the error number and the message associated with the error.

6楼: to 52free:
果然是这个问题!

改成:
procedure LoadForm;
begin
//Application.Handle := Handle;
//ApplicationName := AppName;
Form1 := TForm1.Create(Application);
就行.
它原来那个句柄是做什么用的?

记账软件版7楼: 帮顶!

╭=========================================╮

80G海量源代码,控件,书籍全免费狂下不停!

http://www.source520.com

╰=========================================╯

8楼: 接受答案了.