-1

对不起..我不懂英文...

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

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

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;

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

4

1 回答 1

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;
于 2012-06-10T17:12:25.853 回答