如下:
DLL工程文件单元:
program pass;uses
SysUtils,
Classes,
setpasswordfrm in 'setpasswordfrm.pas' {setpasswordform};exports
SetPassWord;
begin
end.
DLL封装的表单单元:
unit setpasswordfrm;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Tsetpasswordform = class(TForm)
Label1: TLabel;
Edit1: TEdit;
okbtn: TButton;
cancelbtn: TButton;
procedure FormCreate(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
Verified: Boolean;
public
PassWord: PChar;
end;
function SetPassWord(PWord: PChar): Boolean;
implementation{$R *.dfm}procedure Tsetpasswordform.FormCreate(Sender: TObject);
begin
Verified := False;
PassWord := StrAlloc(40);
OKBtn.Enabled := False;
Label1.Caption := 'Please Input PassWord:';
end;procedure Tsetpasswordform.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Edit1.text = '' then Exit;
if Key = #13 then
begin
if Verified then
if StrPas(PassWord) = Edit1.text then
begin
OKBtn.Enabled := True;
Edit1.Enabled := False;
OKBtn.SetFocus;
end
else
begin
Verified := False;
MessageDlg('PassWord is InValid.',mtWarning,[mbOK],0);
Edit1.text := '';
PassWord := '';
Label1.Caption := 'Please Input PassWord:';
end
else
begin
Verified := True;
StrPCopy(PassWord,Edit1.text);
Edit1.text := '';
Label1.caption := 'Please Verify PassWord:';
end;
Key := #0;
end;
end;
function SetPassWord(PWord: PChar): Boolean;
var
SetPassWordForm: TSetPassWordForm;
begin
Result := False;
SetPassWordForm := Tsetpasswordform.Create(application);
try
with SetPasswordForm do
if ShowModal = mrOK then
begin
StrCopy(PWord,StrUpper(Password));
Result := True;
end;
finally
SetPasswordForm.Free;
end;
end;
end.调用DLL程序单元:
unit Unit1;interfaceuses
Windows,Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
function SetPassWord(PWord: PChar):BOOLEAN;far;external 'pass';procedure TForm1.Button1Click(Sender: TObject);
//VAR
//password:pchar;
begin
PassWord := StrAlloc(40);
if SetPassWord(PassWord) = False then
MessageDlg('PassWord is not set',mtInformation,[mbOK],0);end;procedure TForm1.FormCreate(Sender: TObject);
beginend;end.DLL编译通过,但程序中调用DLL行程序运行不了,一按运行就到了工程单元的Begin.
应如何解决,请大家看看(第一次学习DLL,搞了一上午了,急得不得了。)
DLL工程文件单元:
program pass;uses
SysUtils,
Classes,
setpasswordfrm in 'setpasswordfrm.pas' {setpasswordform};exports
SetPassWord;
begin
end.
DLL封装的表单单元:
unit setpasswordfrm;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Tsetpasswordform = class(TForm)
Label1: TLabel;
Edit1: TEdit;
okbtn: TButton;
cancelbtn: TButton;
procedure FormCreate(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
Verified: Boolean;
public
PassWord: PChar;
end;
function SetPassWord(PWord: PChar): Boolean;
implementation{$R *.dfm}procedure Tsetpasswordform.FormCreate(Sender: TObject);
begin
Verified := False;
PassWord := StrAlloc(40);
OKBtn.Enabled := False;
Label1.Caption := 'Please Input PassWord:';
end;procedure Tsetpasswordform.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Edit1.text = '' then Exit;
if Key = #13 then
begin
if Verified then
if StrPas(PassWord) = Edit1.text then
begin
OKBtn.Enabled := True;
Edit1.Enabled := False;
OKBtn.SetFocus;
end
else
begin
Verified := False;
MessageDlg('PassWord is InValid.',mtWarning,[mbOK],0);
Edit1.text := '';
PassWord := '';
Label1.Caption := 'Please Input PassWord:';
end
else
begin
Verified := True;
StrPCopy(PassWord,Edit1.text);
Edit1.text := '';
Label1.caption := 'Please Verify PassWord:';
end;
Key := #0;
end;
end;
function SetPassWord(PWord: PChar): Boolean;
var
SetPassWordForm: TSetPassWordForm;
begin
Result := False;
SetPassWordForm := Tsetpasswordform.Create(application);
try
with SetPasswordForm do
if ShowModal = mrOK then
begin
StrCopy(PWord,StrUpper(Password));
Result := True;
end;
finally
SetPasswordForm.Free;
end;
end;
end.调用DLL程序单元:
unit Unit1;interfaceuses
Windows,Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
function SetPassWord(PWord: PChar):BOOLEAN;far;external 'pass';procedure TForm1.Button1Click(Sender: TObject);
//VAR
//password:pchar;
begin
PassWord := StrAlloc(40);
if SetPassWord(PassWord) = False then
MessageDlg('PassWord is not set',mtInformation,[mbOK],0);end;procedure TForm1.FormCreate(Sender: TObject);
beginend;end.DLL编译通过,但程序中调用DLL行程序运行不了,一按运行就到了工程单元的Begin.
应如何解决,请大家看看(第一次学习DLL,搞了一上午了,急得不得了。)
解决方案 »
- 请教delphi7登陆问题
- 这个问题谁来解决!分全给他!
- 客户端程序怎样读取服务器主机的日期和时间?
- 安装EhLib 3.0控件时总是出错!
- 用代码动态创建一个dbgrid,为什么执行后窗体上不能显示dbgrid?(在线)
- 提示语法错误,麻烦查错!!好急呀,急死了!!!
- 急需求购delphi GPRS远程抄表软件源代码(C/S结构).
- delphi 7調用codesoft 問題
- YV12格式转RGB,PChar 和 PByte 问题
- <<<<<好笑话难找啊。tpagecontrol问题。
- 在Delphi中有没有替换函数???
- 用InstallShield6.3制作安装盘,怎么加快捷方式和程序菜单?
改成
SetPassWordForm := Tsetpasswordform.Create(NIL);看看行不行,别忘了
setpassowrdform.free;
exports
SetPassWord;
并且在DLL单元中在SetPassWord函数最后加上关键字stdcall;
然后在调用单元中写
TSetPassWord = function (PWord: PChar):boolean;stdcall;
调用代码
var
SetPassWord :TSetPassWord;
begin
保证是先加载数据库
......
得到函数在DLL中的地址
调用函数
end;
myling(阿德):加了stdcall也不行啊
//这个加上路径后缀名试试,还要加上导出函数名
myling(阿德) :按你说的做搞定(我上午就是没家DLL后缀),谢谢给分。