[SOLVED] Delphi XE5 - Android application: IdTcpClient crash when close app [Edit]

Hello,

I have a very simple program that works perfectly.
But if I add a TIdTcpClient component on my form, with no change in the properties or event, just add it,  then application crash when exiting with the hardware return button.

What is wrong ?

thank you
Franck

{code}
unit FormTestModbusXE;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.TabControl, FMX.StdCtrls, FMX.Edit, FMX.Layouts,
  FMX.ListBox, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient;

type
  TForm1 = class(TForm)
    TabControl1: TTabControl;
    TabItem1: TTabItem;
    TabItem2: TTabItem;
    TabItem3: TTabItem;
    TabItem4: TTabItem;
    ListBox1: TListBox;
    LabelIP: TLabel;
    Edit1: TEdit;
    LabelPort: TLabel;
    Edit2: TEdit;
    BtnConnect: TButton;
    IdTCPClient1: TIdTCPClient;
    procedure BtnConnectClick(Sender: TObject);
  private
    { Déclarations privées }
    IdTcpClient : TIdTcpClient;
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

uses FMXCommon;

//------------------------------------------------------------------------------------------------------------------------------

procedure TForm1.BtnConnectClick(Sender: TObject);
begin
  ListBox1.items.add('Connecting');
end;

end.
{code}
0
franck
4/10/2014 9:14:27 AM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

5 Replies
1927 Views

Similar Articles

[PageSpeed] 40

franck wrote:

> But if I add a TIdTcpClient component on my form, with no change
> in the properties or event, just add it,  then application crash when
> exiting with the hardware return button.

Crash in what way exactly?  What kind of device/OS are you running your app 
on?  Have you tried debugging the app yet?  Please be more specific.

--
Remy Lebeau (TeamB)
0
Remy
4/8/2014 5:54:01 PM
Dear Remy,

Thank you to reply.
I use a Galaxy S3.
When I close the application from the device by the "hardware" key (return key) then the application close and 1 seconde after I have a message to the screen with a OK button which says <Application name> has stopped (I am not sure if the english version of Android uses exactly the same words because it is my translation of the french message)

In debug mode, delphi report this error: "Le projet <myProjectName> a declenche la classe d'exception Segmentation fault (11)."
I think that we can translate this message by 'The project <myProjectname> has raised the exception class Segmentation fault (11)."

This error occured on the line  " GStackCriticalSection.Acquire;" in the file IdStack and function DecUsage:
{code}
In file IdStack.pas:
(...)
class procedure TIdStack.DecUsage;
begin
  Assert(GStackCriticalSection<>nil);
  GStackCriticalSection.Acquire; ==> exception here !!!
  try
    // This CS will guarantee that during the FreeAndNil nobody
    // will try to use or construct GStack
    if GInstanceCount > 0 then begin
      Dec(GInstanceCount);
      if GInstanceCount = 0 then begin
        FreeAndNil(GStack);
      end;
    end;
  finally
    GStackCriticalSection.Release;
  end;
end;
{code}

regards,
0
franck
4/9/2014 9:31:23 AM
franck wrote:

> In debug mode, delphi report this error: "Le projet <myProjectName> a
> declenche la classe d'exception Segmentation fault (11)."

That is the equivilent of an AccessViolation on Windows.  Invalid memory 
is being accessed.

> This error occured on the line  " GStackCriticalSection.Acquire;" in
> the file IdStack and function DecUsage:

The only way I could see that happpening is if DecUsage() is being called 
after the IdStack unit has already been finalized, since that is when GStackCriticalSection 
gets freed.  DecUsage() is called in TIdComponent.Destroy() when any Indy 
component is freed.

TIdStack.IncUsage() is called in TIdComponent.InitComponent(), which is *supposed* 
to be called during every Indy component creation.  One thing I never got 
confirmation on is whether InitComponent() is actually called correctly on 
mobile platforms.  But that would not affect this particular issue.

--
Remy Lebeau (TeamB)
0
Remy
4/9/2014 7:16:07 PM
Hi Remy,

Well, it is a bug of the component TIdTCPClient.
We can solve this issue by removing the component TIdTCPClient from the form and create it like this :

{code}
procedure TTestModbusForm.FormCreate(Sender: TObject);
begin
  idTCPClient := TIdTCPClient.Create(nil); // DO NOT ENTER "Create(SELF)" BECAUSE IT WILL CRASH WHEN CLOSING THE APPLICATION
  idTCPClient.ConnectTimeout := 3000;
  idTCPClient.ReadTimeout    := 3000;
End;
{code}

then I destroy it  like this:
{code}
procedure TTestModbusForm.FormDestroy(Sender: TObject);
begin
  FreeAndNil(idTCPClient);
end;
{code}

Thanks 
Franck
0
franck
4/10/2014 9:13:25 AM
franck wrote:

> Well, it is a bug of the component TIdTCPClient.
> We can solve this issue by removing the component TIdTCPClient
> from the form and create it like this :

That does not necessarily indicate a bug in TIdTCPClient itself.  That sounds 
more like a bug in TComponent instead, in the way it manages owned components 
under ARC.  Without seeing the call stack when the exception occurs, it is 
difficult to know what exactly is crashing.

--
Remy Lebeau (TeamB)
0
Remy
4/10/2014 4:50:20 PM
Reply:

Similar Artilces:

Delphi XE5(U2) Firemonkey application crashes at startup on OSX on new mac [Edit]
Hello, I'm trying to deploy my first application on a mac platform. I have successfully built the application on my dev mac and run it through PAServer and now I would like to deploy it on a different MacOS. I tried to drag and drop the application .app file into the application folder of the new Mac. The app shows up but as soon as I start it, I got a message telling me that it stopped unexpectedly. I'm really lost here: With windows, I'd have no problem finding out what is wrong but, with a Mac, I haven't got a clue what I did wrong. The application doesn't do an...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

New video of camera surveillance app made with Delphi XE5 and FireMonkey [Edit]
Hello guys I know that most of you have already seen the video from our mobile camera surveillance system, but today I uploaded a new video showing the final version, which has a much better interface than the previous version, along with some nice features that you all will like to see. I would recommend the PTZ and Virtual Matrix sections which shows some nice GUI controls made with Firemonkey http://www.youtube.com/watch?v=4lQGA8-sO9w The app is also available for download for Android, instructions are available on the video description > {quote:title=Eric Fleming Bonilha w...

calling a c++ dll from a delphi vcl app crashes the app upon exit [Edit]
I am using RAD Studio 2010 and I downloaded the latest updates. Since I can't see how I can attach a file to the message, I included in this message the source code for each file: To reproduce this problem follow these steps: Create a project group with two projects, one c++ dll project and one a Delphi VCL forms project. Save all the files in the same folder. 1. Use the wizard to create the c++ dll project, select c++ & Use VCL checkboxes. Make sure Project Options->C++ Linker->Dynamic RTL is set to true. I also added memmgr.lib and sharemem.obj to the project but I bel...

How to build enterprise-grade Delphi app
Hi It would be nice to build enterprise-grade appl with Delphi, but are the options or third party software (like in J2EE) to do this? e.g. 1) there is J2EE middleware for hosting components - developer is not required to handle all the issues that are connected with session handling and different contexts in which the components can be stored (like application, session, request context, etc.). I understand that some of this can be done in DataSnap or in Web Services (can be even PHP, Java or .NET) and Delphi client - but in both cases there are some drawbacks: - for DataSnap - much shou...

Delphi XE3 crashes when closing Word 2010 [Edit]
After changing from Delphi 6 to XE3 my program crashes when i close a Word-Document opened by the program using OLE-Automation. So i created a very simple Test-Program with only one Form, a TWordApplication and a TWordDocument (and of course a TButton...). On ButtonClick i connect to Word and open a document. If i close Word or the Document all is working fine. Then i assigned an eventhandler to WordApplication.OnDocumentBeforeClose. If i then close the Document my program crashes calling the eventhandler in TWordApplication.InvokeEvent. Has anyone seen this problem and maybe a so...

Does Delphi XE5 firemonkey work on current Samsung tablets? [Edit]
I am being told that Delphi XE5 with firemonkey will not work on the current range of Samsung tablets even if they have Android 4 is that true? If so I will be very disappointed having invested thousands of pounds and a few hundred hours to adopt the technology on the promise I can now deploy to Android mobile devices. When I run even the most simple Hello World app I simply get a black screen on my brand new Samsung tablet. I am told it only works on Android devices with a ARMv7 CPU supporting NEON instruction sets. If this is the case developers need to know that I have been told today ...

Firemonkey app from Delphi XE2 -> Dropbox & iCloud [Edit]
Im developing an app for iOS and MacOS Is there any component or a way to connect to Dropbox and iCloud using Delphi XE2? > {quote:title=laureano bonilla wrote:}{quote} > Im developing an app for iOS and MacOS > > Is there any component or a way to connect to Dropbox and iCloud using Delphi XE2 For iCloud, you will need support for both iOS 5.0 and 10.7 Lion. I don't believe XE2 even supports the classes added with iOS 4.x, much less 5.0, although you can parse the iOS 5.0 UIKit and Foundation headers yourself: http://web.me.com/macpgmr/ObjP/Xcode4/iOS_5_Parsing_...

Delphi XE5 Update 2
I should have 8 options. I see just the first 2: Blank Application and 3d Application. http://docwiki.embarcadero.com/RADStudio/XE5/en/FireMonkey_Mobile_Application_Templates How can I get the others to appear? Kyle Miller wrote: > I should have 8 options. I see just the first 2: Blank Application and 3d Application. > http://docwiki.embarcadero.com/RADStudio/XE5/en/FireMonkey_Mobile_Application_Templates > > How can I get the others to appear? > I've seen this happen for C++, but not for Delphi. If you launch with the -r option I expect they'll be there. -...

Delphi 2010 application starts in Windows XP. Not if recompiled with XE5 [Edit]
Hello, we have developed a 32 bit application that must run under Windows XP (thousands of independent customers worldwide). It works perfectly if compliled with Delphi 2010 Professional. Recompiling it with Delphi XE5 (target platform Win 32) it starts but after some instants it shows a message like this: The procedure entry point InitializeConditionVariable could not located in the dynamic library Kernel32.dll. Of course this is due to such procedure only being available with Windows Vista and later. Running a "dependency walk" software on the executable, we indeed se...

Touch Gestures in Firemonkey 3D application Delphi XE3 MacOS [Edit]
Hi! I'm trying to create a MacOS Firemonkey 3D application with gestures enabled but I can't make it work. I can place a GestureManager on the form but there is no Touch property on the TForm3D object. Then I've tried to create a TLayer3D with a normal TPanel where I was able to set the Touch property but the gestures didn't work although it captured any other mouse movements. Then I've created a separate HD TForm with a GestureManager and with the Touch property set which worked as a stand alone form but whe n I've linked a touch enabled TPanel on the HD TForm to t...

Embedding an external application into the Delphi application [Edit]
Hi guys, I am trying to embed Mozilla Firefox into my Delphi application with the following code, The code works with "Notepad" but it doesn't work with the Mozilla Firefox. Any help will be extremely appreciated. {code} unit unitMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ShellApi; type TfrmMain = class(TForm) pnlTop: TPanel; panBottom: TPanel; btnLoadApp: TButton; btnKill: TButton; procedure btnLoadAppClick(Sender: TObject); procedure btnKill...

[Partially solved] Delphi XE5 need Help for Apple APN and Google GCM [Edit]
Hi, i have developed an App now in App Store "Sisa Service", have buy XE5 and port App from XE4 to XE5 to have one code for iOs and Android the only problem that i have to solve is receive Push Message from Apn for Apple and GCM for Android but i haven't find documentation that explaines how to. Pls i hope someone can help me, without this functionality i can't post new App in Apple Store and Google Play and i think that Push Messages are very important function for mobile development. Ty Manuel Di Maio Edited by: Manuel Di Maio on Sep 19, 2013 12:44 PM for iOS I...

Converting from Delphi 2005 to Delphi XE5
I have developed a number of Windows applications in Delphi 2005. I recently purchased Delphi XE5. I have started by trying to compile an existing 2005 application. I am getting a 7 errors about FMXTeeEditor. [dcc32 Error] E1026 File not found: 'FMXTee.Editor.Brush.fmx' Not able to find a solution to this. Any help greatly appreciated. Did you open every form before compiling? The old forms get updated with new properties when they are opened. I would make a copy of the old project before doing any of this. maybe you have links to the older tchart files....i.e its not usi...

Delphi 7 app to web app conversion [Edit]
My company has an old Windows engineering application that we would like to convert to a web application so that we can offer it as a software as a service. The application is written primarily in Delphi 7 with the heavy number crunching done in Fortran (I did say it was old!). We would like to reuse as much of the existing Delphi code as possible and only modify the Fortran enough so that it will run in the background on the web server. We have never developed a web application so we're looking for guidance on the best way to make this conversion. Our questions at this point: ...

Web resources about - [SOLVED] Delphi XE5 - Android application: IdTcpClient crash when close app [Edit] - embarcadero.delphi.firemonkey

Resources last updated: 2/9/2016 1:50:32 AM