TIdTCPClient and MessageDlg in Android 6 with Delphi XE8

  

I try the next code in an android app in Delphi XE8;

function CheckInternet(idTCP: TIdTCPClient): boolean;
begin
try
idTCP.ReadTimeout := 4000;
idTCP.ConnectTimeout := 4000;
idTCP.Port := 80;
idTCP.Host := ‘google.com’;
idTCP.Connect;
idTCP.Disconnect;
result:=true;
except
result:=false;
end;
end;

Then I check in main form if internet connection is available;

if Not CheckInternet(IdTCPClient1) then
MessageDlg(‘Internet connection not available’, TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbOK], 0, procedure(const AResult: TModalResult) begin Application.Terminate; end);

Works fine in Android versions like 4.x and 5.x, but in Android version 6.x the program exits without display any message, otherwise if don’t check for the internet connection, the message is displayed.
Please, Did anybody known about this issue?.

With an anonymous thread also does not works;

TThread.CreateAnonymousThread(procedure
begin
try
IdTCPClient1.ReadTimeout := 4000;
IdTCPClient1.ConnectTimeout := 4000;
IdTCPClient1.Port := 80;
IdTCPClient1.Host := ‘google.com’;
IdTCPClient1.Connect;
IdTCPClient1.Disconnect;
except
MessageDlg(‘Internet connection not available’, TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbOK], 0,
procedure(const AResult: TModalResult) begin TThread.CurrentThread.Free; Application.Terminate; end);
end;

end).Start;

Updated code;

TThread.CreateAnonymousThread(procedure
begin
IdTCPClient1.ReadTimeout := 4000;
IdTCPClient1.ConnectTimeout := 4000;
IdTCPClient1.Port := 80;
IdTCPClient1.Host := ‘google.com’;
IdTCPClient1.Connect;
IdTCPClient1.Disconnect;

TThread.CurrentThread.OnTerminate := AnonymousThreadTerminate;

end).Start;

procedure AnonymousThreadTerminate(Sender: TObject);
begin
MessageDlg(‘Internet connection not available’, TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbOK], 0, procedure(const AResult: TModalResult) begin Application.Terminate; end);
end;

Many thanks and Regards.

Comments are closed.