1

Basic facts:

The application was created as a multiplatform default empty application.

  • Wordpress is on a NonSSL connection.
  • On windows the code (below) works flawlessly.
  • On Android the data is being received by the server flawlessly, However the application is being shut down. Debug shows the exception IdConnClosedGracefully
  • The "try except" does not intercept the exception.
  • XE8, indy 10

Questions:

  • Am I doing something wrong?
  • Why is the exception not being intercepted.
  • What can I do to prevent the shutdown?

the code:

procedure TForm8.Button1Click(Sender: TObject);
var
    LPostURL    : String;
    LXMLStream : TMemoryStream;
    LHttp: TIdHttp;
begin
    TTask.Run(procedure
  var
      LPostURL    : String;
      LXMLStream : TMemoryStream;
      LResStream : TMemoryStream;
      LHttp: TIdHttp;
  begin
    LHttp := TIdHTTP.Create;
    LHttp.HTTPOptions := LHttp.HTTPOptions - [hoForceEncodeParams];
    LHttp.HandleRedirects:=true;
    buildpost;
    xml.Active:=true;
    LPostURL   := 'http://benkyo.tk/xmlrpc.php';//edit1.Text;
    LXMLStream := TMemoryStream.Create;
    XML.SaveToStream(LXMLStream);
    try
      try
          memo1.lines.text:=LHttp.post(LPostURL, LXMLStream);
      except
        on E:exception do
        memo1.Lines.Text:=('IdHTTP1.Post error'+ E.Message);
      end;
    finally
      LHttp.Free;
      LXMLStream.Free;
    end;
  end);
end;
LU RD
  • 34,438
  • 5
  • 88
  • 296
rafiw
  • 31
  • 1
  • 9
  • Please try to put some effort in formatting the question. – Gurwinder Singh Dec 24 '16 at 04:53
  • The GUI can only safely be accessed from the main thread. `memo1.lines.Text := ` must be synchronized. – LU RD Dec 24 '16 at 11:05
  • See [Update a VCL component from CreateAnonymousThread](http://stackoverflow.com/q/6739595/576719) and [Delphi: Why VCL is not thread-safe? How can be?](http://stackoverflow.com/q/28655758/576719) – LU RD Dec 24 '16 at 11:20
  • I tried it with straight procedure (not anonymous) – rafiw Dec 24 '16 at 12:10
  • I also tried it without access to any GUI, without looking at the returned string, the result is the same – rafiw Dec 24 '16 at 12:12
  • I also tried it with a memory stream that accepts the returned string, the problem persists – rafiw Dec 24 '16 at 12:15
  • Part of your question appears to be a duplicate of http://stackoverflow.com/q/1234950/33732. Not sure about the rest. Please don't ask multiple questions in a single post. It makes the site harder to organize. – Rob Kennedy Dec 24 '16 at 14:33
  • Thank you Rob, I have read your article, it is interesting, but I could not find an answer my question. My question is: Even though I turned off the debugger As you suggest, On Android my "except" clause is never executed. WHY? – rafiw Dec 24 '16 at 15:21

0 Answers0