function setjz(url:string;account:string;jz:double):string;export;stdcall;
var
aStream:TStringStream;
sparam:TStrings;
posturl,str1,str2:string;
IdHTTP1:TIdHTTP;
beginastream:=TStringStream.Create('');
sparam:=tstringlist.Create;
 
idhttp1:=tidhttp.Create(nil);
try
str1:='account='+account;
sparam.Add(str1);
str1:='jz='+floattostr(jz);
sparam.add(str1);
posturl:=url+'/send.php';
sparam.Add(str1);
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP1.Post(posturl, sparam, aStream); //Ìá½»
//str2:=idhttp1.AllData;
str2:=trim(astream.DataString);//»ñÈ¡½á
sparam.Free;
FreeAndNil(idhttp1);
astream.Free;
result:=str2;
except
FreeAndNil(idhttp1);
sparam.Free;
astream.Free;
result:='';
end;
end;代码如上,在程序中调用本函数,第一次调用很正常,第二次调用就报错,调试发现错误出在 
idhttp1:=tidhttp.Create(nil);这一句,我的delphi版本是D7,请大家帮忙解决一下,深表感谢

解决方案 »

  1.   

    function getxdhttp(url:string;account:string):string;
    var
    aStream:TStringStream;
    sparam:TStrings;
    posturl,str1,str2:string;
    IdHTTP1: TIdHTTP;
    beginastream:=TStringStream.Create('');
    sparam:=tstringlist.Create;
    idhttp1:=tidhttp.Create(nil);
    idhttp1.HandleRedirects:= true; 
    try
    str1:='account='+account;
    sparam.Add(str1);
    posturl:=url+'/get.php';
    sparam.Add(str1);
    IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
    IdHTTP1.Post(posturl, sparam, aStream); //Ìá½»
    str2:=trim(astream.DataString);//»ñÈ¡½á
     
    finally
    sparam.Free;
    IdHTTP1.Disconnect;
    idhttp1.Free;
    //FreeAndNil(idhttp1);
    astream.Free;
    end;result:=str2;
    end;看了网上的文章将程序改成如上,错误依旧,第一可以正常调用,第二次失败
      

  2.   

    加上判断试试,怀疑没完全释放!if IdHTTP1 = nil then
      idhttp1:=tidhttp.Create(nil); 
      

  3.   

    楼上的意见,我测试了一下,还是不行,而且每次调试到那里的时候,观察idhttp1的值就是nil,不知道为什么第二次调用这个函数就报错。
      

  4.   

    调用代码如下,那个dll里面只有两个函数
    unit test;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        Edit4: TEdit;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;function   getxdstr(url:string;account:string):string;stdcall;
    far;external 'easer.dll'name 'getxdstr';function setjz(url:string;account:string;jz:double):string;stdcall;
    far;external 'easer.dll'name 'setjz';implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
    edit4.Text:=getxdstr(edit1.text,edit2.text);end;procedure TForm1.Button2Click(Sender: TObject);
    begin
    setjz(edit1.text,edit2.text,strtofloat(edit3.text));
    end;end.
      

  5.   

    已经搞定了,dll要比写程序麻烦多了,谢谢大家