第一种情况如下,无论是否在DLL中改变li的值,都一切正常。
function login(var li:string):WordBool;Far;External 'mylogin.dll';
var
li:string;
begin
Application.Initialize;
initsystem;
///////li:='10';
if login(li) then
begin
Application.CreateForm(TfrmMain, frmMain);
Application.run;
end
else
Application.Terminate;
end.第二种情况如下:在DLL中改变li的值,关闭主窗体时报无效的指针错误,有时也报AV错误。
function login(var li:string):WordBool;Far;External 'mylogin.dll';
var
li:string;
begin
Application.Initialize;
initsystem;
li:='10';
if login(li) then
begin
Application.CreateForm(TfrmMain, frmMain);
Application.run;
end
else
Application.Terminate;
end.
请高手指点,另外,如果li为integer型,就一点错误也没有。DLL中部分代码如下:function login(var li:string):WordBool;
begin
iclick:=0; //计数器,最多输入三次口令;
result:=false;
frmLogin:=TfrmLogin.create(application);
try
if frmLogin.showmodal=mrOK then
with frmLogin do
begin
li:=edit1.Text;
result:=true;
end;
finally
frmLogin.Close;
frmLogin.free;
end;
end;
procedure TfrmLogin.LbSpeedButton1Click(Sender: TObject);
begin
ModalResult:=mrOK;
end;
procedure TfrmLogin.LbSpeedButton2Click(Sender: TObject);
begin
modalresult:=mrCancel;
end;
function login(var li:string):WordBool;Far;External 'mylogin.dll';
var
li:string;
begin
Application.Initialize;
initsystem;
///////li:='10';
if login(li) then
begin
Application.CreateForm(TfrmMain, frmMain);
Application.run;
end
else
Application.Terminate;
end.第二种情况如下:在DLL中改变li的值,关闭主窗体时报无效的指针错误,有时也报AV错误。
function login(var li:string):WordBool;Far;External 'mylogin.dll';
var
li:string;
begin
Application.Initialize;
initsystem;
li:='10';
if login(li) then
begin
Application.CreateForm(TfrmMain, frmMain);
Application.run;
end
else
Application.Terminate;
end.
请高手指点,另外,如果li为integer型,就一点错误也没有。DLL中部分代码如下:function login(var li:string):WordBool;
begin
iclick:=0; //计数器,最多输入三次口令;
result:=false;
frmLogin:=TfrmLogin.create(application);
try
if frmLogin.showmodal=mrOK then
with frmLogin do
begin
li:=edit1.Text;
result:=true;
end;
finally
frmLogin.Close;
frmLogin.free;
end;
end;
procedure TfrmLogin.LbSpeedButton1Click(Sender: TObject);
begin
ModalResult:=mrOK;
end;
procedure TfrmLogin.LbSpeedButton2Click(Sender: TObject);
begin
modalresult:=mrCancel;
end;
设置你的调用程序,或者%windir%\system32\rundll.exe
用PCHAR后是不报错了
我在主程序中赋了初值
在DLL中进行修改
但是发现在回到主程序时变量还是初值,没有修改?怎么回事?谢谢
library Project1;{ 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;{$R *.res}begin
end.