function GetSNP(FHandle:THandle;var S:pChar;var N:pChar;var P:pChar):Boolean;export;stdcall;
var
LoginForm:TForm1;
begin
Application.handle:=FHandle;
result:=false;
S:=pchar('');
N:=Pchar('');
P:=Pchar('');
LoginForm:=TForm1.Create(Application);
try
if LoginForm.ShowModal =mrok then
begin
       if (Length(LoginForm.txtLoginService.Text )=0) or (Length(LoginForm.txtLoginName.Text )=0) then
       begin
               MessageDlg('请将数据填写完整,服务器名称和用户名不能为空',mterror,[mbOk], 0);
               exit;
       end;
       S:=pchar(LoginForm.txtLoginService.Text);
       N:=pchar(LoginForm.txtLoginName.Text);
       P:=pchar(LoginForm.txtLoginPass.Text);
       result:=true;
end
finally
LoginForm.free;
end;
end;比如我在文本框中输入test1,通过N返回的值却是test。邪门了!!!!!!!!!!!!  

解决方案 »

  1.   

    pchar型改为string型试试,然后再进行类型转换,用pchar。
      

  2.   

    老大!!!你的PChar使用方法不正确!!!S:=pchar(LoginForm.txtLoginService.Text);
    如果你的LoginForm销毁了,那么S指向什么???其他的道理一样!!!有两种方式可以解决你的问题:
    1、在外部申请内存;(这种便于管理)
    2、在内部申请内存;(这种不便于管理,因为不知道动态分配内存的大小!!!)正解:
    1、在调用前为S申请一个足够大的空间,有点类似调用Windows API函数GetWindowDirectory
    2、使用StrPCopy将LoginForm.txtLoginService.Text的内容复制到S中
    3、使用S
    4、释放S,如果不释放将产生内存漏洞!!!