为了发布列表框项IDHTTP?

时间:2012-06-10 08:00:58

标签: delphi for-loop

抱歉..我不懂英语......

我想向他们发送所有列表框项目。

我的代码(发送到第一项);

var
  i: Integer;
  satir: Integer;
  str: TStringList;
  response: TStringStream;
begin
  str := TStringList.Create;
  Response:= TStringStream.Create('');
  satir := ListBox1.Items.Count;
  try
    str.Clear;
    IdHTTP1.Disconnect;

    str.Add('author='+Edit1.Text+'');
    str.Add('email='+Edit2.Text+'');
    str.Add('url='+Edit3.Text+'');
    str.Add('comment='+Memo1.Text+'');
    str.Add('comment_post_ID='+'1'); // Hidden items. When I delete the error does not.
    for i:= 0 to satir do 
    begin 
      IdHTTP1.Post(ListBox1.Items.strings[i],str,Response);
      IdHTTP1.Disconnect;
      MessageDlg('Ok.', mtinformation,[mbOK],0);
    end;
  except
    on e: exception do 
    begin
      str.Free;
      Response.Free;
    end;
  end;
end;

如果你纠正我的错误,我会很高兴。

1 个答案:

答案 0 :(得分:1)

您的代码中存在一些拼写错误和泄漏。试试这个:

var
  i: Integer;
  satir: Integer;
  str: TStringList;
begin
  satir := ListBox1.Items.Count;
  str := TStringList.Create;
  try
    IdHTTP1.Disconnect;

    str.Add('author='+Edit1.Text+'');
    str.Add('email='+Edit2.Text+'');
    str.Add('url='+Edit3.Text+'');
    str.Add('comment='+Memo1.Text+'');
    str.Add('comment_post_ID='+'1'); // forgot it. Hidden item. Could this be the problem?
    for i:= 0 to satir-1 do 
    begin 
      try
        IdHTTP1.Post(ListBox1.Items.Strings[i], str);
        MessageDlg('Ok', mtinformation, [mbOK], 0)
      except
        on E: Exception do
          MessageDlg('Error: ' + E.Message, mtError, [mbOk], 0);
      end;
      IdHTTP1.Disconnect;
    end;
  finally
    str.Free;
  end;
end;