-1

sorry.. I know little english...

I want to send them all listbox items.

My codes (sent to the first item);

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;

If you correct my mistakes I would be happy.

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 に答える