ShowModal for Android Delphi XE5 Update 2, got access violation

Hello everyone,

I've done my iOS app, try to compile to android system.
But I found the showmodal doesn't work that way, I understand that, Android does different with iOS, then I wrote a testing app with existing demo source "ScrollableFormDemo"
I added a second form in that probject called TForm1 and A Button in the main form.


procedure TFormMain.Button1Click(Sender: TObject);
begin
  Form1 := TForm1.Create(nil);
  Form1.ShowModal(
    procedure(ModalResult: TModalResult)
    begin
      // if OK was pressed and an item is selected, pick it
      Form1.DisposeOf;
    end
    );
end;

procedure TForm1.ListBoxItem1Click(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

then I got access violation, is here anyone knows why?

Thanks.
0
hao
1/9/2014 5:52:04 AM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

7 Replies
3860 Views

Similar Articles

[PageSpeed] 22

hao wrote:

> then I got access violation, is here anyone knows why?

Calling Form1.DisposeOf() frees the Form object immediately, regardless of 
current its reference count.  At least in non-mobile environments, ShowModal() 
accesses the Form object after the Form has closed before ShowModal() exits 
to the caller, so you cannot free the Form while ShowModal() is still running. 
 I looked at the FMX source code and the anonymous procedure is called when 
the Form's ModalResult property is assigned for the first time once ShowModal() 
has begin running.  So you have to make sure that none of your code accesses 
the Form object for ANY reason once the ModalResult has been set, because 
the Form object will not be alive anymore.

--
Remy Lebeau (TeamB)
0
Remy
1/9/2014 8:50:33 PM
> {quote:title=hao hao wrote:}{quote}
> 
> then I got access violation, is here anyone knows why?
> 
> Thanks.

From your code it looks like Form1 is already declared somewhere - maybe try using a local variable inside your TFormMain.Button1Click event?

http://blog.marcocantu.com/blog/xe5_anonymous_showmodal_android.html - You might have already seen this, but it could be useful.

Edit: You could also check to make sure Form1 isn't getting created in the project source file.
0
Michael
1/9/2014 9:38:48 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> hao wrote:
> 
> > then I got access violation, is here anyone knows why?
> 
> Calling Form1.DisposeOf() frees the Form object immediately, regardless of 
> current its reference count.  At least in non-mobile environments, ShowModal() 
> accesses the Form object after the Form has closed before ShowModal() exits 
> to the caller, so you cannot free the Form while ShowModal() is still running. 
>  I looked at the FMX source code and the anonymous procedure is called when 
> the Form's ModalResult property is assigned for the first time once ShowModal() 
> has begin running.  So you have to make sure that none of your code accesses 
> the Form object for ANY reason once the ModalResult has been set, because 
> the Form object will not be alive anymore.
> 
> --
> Remy Lebeau (TeamB)


Thanks for reply. I understand the DisposeOf will free all the form.
But Form1 is very very simple and doesn't do any extra work. I can't see anywhere the app
try to access the form once the modalresult has been set.

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.ListBox,
  FMX.Layouts, FMX.StdCtrls;

type
  TForm1 = class(TForm)
    ToolBar1: TToolBar;
    ListBox1: TListBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    ListBoxItem4: TListBoxItem;
    procedure ListBoxItem1Click(Sender: TObject);
  private
    { Private declarations }
  protected
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

{ TForm1 }


procedure TForm1.ListBoxItem1Click(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

end.
0
hao
1/9/2014 9:46:46 PM
> {quote:title=Michael McFarland wrote:}{quote}
> > {quote:title=hao hao wrote:}{quote}
> > 
> > then I got access violation, is here anyone knows why?
> > 
> > Thanks.
> 
> From your code it looks like Form1 is already declared somewhere - maybe try using a local variable inside your TFormMain.Button1Click event?
> 
> http://blog.marcocantu.com/blog/xe5_anonymous_showmodal_android.html - You might have already seen this, but it could be useful.
> 
> Edit: You could also check to make sure Form1 isn't getting created in the project source file.

Yes I do see this article and my code is kind of learning from this.
Form1 is definitely not in project auto create form.

Edited by: hao hao on Jan 9, 2014 1:50 PM
0
hao
1/9/2014 9:51:12 PM
> {quote:title=Michael McFarland wrote:}{quote}
> > {quote:title=hao hao wrote:}{quote}
> > 
> > then I got access violation, is here anyone knows why?
> > 
> > Thanks.
> 
> From your code it looks like Form1 is already declared somewhere - maybe try using a local variable inside your TFormMain.Button1Click event?
> 
> http://blog.marcocantu.com/blog/xe5_anonymous_showmodal_android.html - You might have already seen this, but it could be useful.
> 
> Edit: You could also check to make sure Form1 isn't getting created in the project source file.

All good now. it's working
Simply move the global variable to be local variable.
And it's only for UI Form variable. 
Thanks guys.


procedure RunStockTakeModule( msiobj : TMobileSessionInfoObj );
*var*
  *frmstocktakeintro: Tfrmstocktakeintro;*
begin
  frmStockTakeIntro := TfrmStockTakeIntro.Create(nil);
  frmStockTakeIntro.msiobj := msiobj;
  {$IFDEF ANDROID}
  frmStockTakeIntro.ShowModal(
    procedure(ModalResult: TModalResult)
    begin
      FreeAForm( frmStockTakeIntro );
    end );
  {$ELSE}
  frmStockTakeIntro.ShowModal;
  FreeAForm( frmStockTakeIntro );
  {$ENDIF}
end;

Edited by: hao hao on Jan 9, 2014 2:28 PM
0
hao
1/9/2014 10:29:23 PM
> {quote:title=Michael McFarland wrote:}{quote}
> > {quote:title=hao hao wrote:}{quote}
> > 
> > then I got access violation, is here anyone knows why?
> > 
> > Thanks.
> 
> From your code it looks like Form1 is already declared somewhere - maybe try using a local variable inside your TFormMain.Button1Click event?
> 
> http://blog.marcocantu.com/blog/xe5_anonymous_showmodal_android.html - You might have already seen this, but it could be useful.
> 
> Edit: You could also check to make sure Form1 isn't getting created in the project source file.


OMG.......I never see delphi doing things like that since Delphi 3.
It seems like following the Android Java development Rule "no global variable"


The code bellow is correct.

procedure TFormMain.Button1Click(Sender: TObject);

var
  frm1 : TForm1;
begin
  frm1 := TForm1.Create(nil);
  frm1.ShowModal(
    procedure(ModalResult: TModalResult)
    begin
      // if OK was pressed and an item is selected, pick it
      frm1.DisposeOf;
    end
    );
end;

but Form1 definitely not in auto-Create form list in project source.

program ScrollableFormDemo;

uses
  FMX.Forms,
  FMX.Types,
  MainFrm in 'MainFrm.pas' {FormMain},
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  VKAutoShowMode := TVKAutoShowMode.vkasAlways;
  Application.FormFactor.Orientations := [TFormOrientation.soPortrait];
  Application.CreateForm(TFormMain, FormMain);
  Application.Run;
end.

For researching I added another variable in Unit1

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.ListBox,
  FMX.Layouts, FMX.StdCtrls;

type
  TForm1 = class(TForm)
    ToolBar1: TToolBar;
    ListBox1: TListBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    ListBoxItem4: TListBoxItem;
    procedure ListBoxItem1Click(Sender: TObject);
  private
    { Private declarations }
  protected
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  frm : TForm1;

implementation

{$R *.fmx}

{ TForm1 }


procedure TForm1.ListBoxItem1Click(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

end.


procedure TFormMain.Button1Click(Sender: TObject);


begin
  frm := TForm1.Create(nil);
  frm.ShowModal(
    procedure(ModalResult: TModalResult)
    begin
      // if OK was pressed and an item is selected, pick it
      frm.DisposeOf;
    end
    );
end;


and it will access violation again.

Edited by: hao hao on Jan 9, 2014 2:17 PM

Edited by: hao hao on Jan 9, 2014 2:29 PM
0
hao
1/9/2014 10:29:52 PM
hao wrote:

> I can't see anywhere the ap try to access the form once the
> modalresult has been set.

It may be getting accessed by the FMX/RTL internally when the ListBox's OnClick 
event handler exits, while the framework is still performing dispatching 
and cleanup operations of the click action.  The Form object is being destroyed 
while that OnClick handler is still running.  One way to work around that 
would be to use TThread.Queue() to delay assignment of the ModalResult, or 
delay calling DisposeOf(), to ensure FMX/RTL is not actively using the Form 
object at the time of destruction, eg:

{code}
procedure TForm1.ListBoxItem1Click(Sender: TObject);
begin
  TThread.Queue(nil,
    procedure
    begin
      ModalResult := mrCancel;
    end
  );
end;
{code}

Or:

{code}
procedure TFormMain.Button1Click(Sender: TObject);
begin
  Form1 := TForm1.Create(nil);
  Form1.ShowModal(
    procedure(ModalResult: TModalResult)
    begin
      TThread.Queue(nil, Form1.DisposeOf);
    end
  );
end;
{code}

--
Remy Lebeau (TeamB)
0
Remy
1/9/2014 11:04:15 PM
Reply:

Similar Artilces:

Delphi XE5 update 2 stops all Android Apps Compiling
Hello Downloaded and installed XE5 Update 2 after un-installing RAD Studio XE5 now none of my Android apps will compile, all of which were compiling before. Get Linkage error message such as:- [DCC Fatal Error] F2588 Linker error code: 1 ($00000001) Tried doing build and deleting .o .dcu and .apk files Checked Android SDK installed and the NDK This is a bad situation and any help most appreciated. Clive Morgan wrote: > [DCC Fatal Error] F2588 Linker error code: 1 ($00000001) If you create a new application for Android, do you have the same issue? -- Dave Nottage ...

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 XE5 Update 2: Is there an update for PAServer ? Version mismatch [Edit]
Is it only a problem with my install or the PAServer was not updated for update 2 ? The folder only contains the original version and the update 1... RADPAServerXE5.pkg RADPAServerXE5_upd1.pkg When I try to run an iOS app the IDE expects version 4.2.0.05 and the PAServer SP1 on OSX is 4.0.1.10b. Thanks Pascal Edited by: Pascal Desjardins on Dec 11, 2013 9:30 AM RADPAServerXE5.pkg is the new one. Giel Thanks, I misread the timestamp on the file... this happens when you have US and French Canadian settings on multiple VM :) > {quote:title=Giel - wrote:}{quote} ...

Delphi XE5 Update 2 Hotfix 6
Hi, Alter applying update2 and hotfixes 1-5 I'm still getting the error: ----------- Unable to launch process on 'LA204.macincloud.com' using the parameters from the 'MacinCloud' profile. The following error was returned: 'Wrapper init failed: (null)' ----------- I'm using mac-in-cloud and can't apply hotfix 6. (I keep getting an error, either the application directory is not found or I'm not allowed to use the sudo command) Has hotfix 6 been released to mac-in-cloud? Gary You need to contact Mac-in-cloud here to find out what they ...

Cannot download the IPWorks for Delphi XE5 Update 2
When i click on the download button for the above mentioned software, the following error appears ============= database file appears corrupt () wrong page type page 75 is of wrong type (expected 4, found 6) An error has occurred while processing the page. Please try to refresh the page, or return to the home page. ============= Please help. thanks chris ...

Accessing an Android Java class from Delphi XE5
Hi! How to translate this C++ code to Delphi XE5 for Android: {code} int bufsize=AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT) {code} I found that there is an 'JAudioTrack' type in 'Androidapi.JNI.Media' but I have no clue how to call this 'getMinBufferSize' function which is for 'JAudioTrackClass'. The problem is I don't know how to instanteniate these Android Java classes for Delphi. Please help! Thank you! > How to translate this C++ code Java rather than C++ surely...? ...

TDBChart and Delphi XE5 Update 2
Hi I've just converted a chart-heavy project from Delphi XE3 to Delphi XE5. I'm using the Standard TeeChart edition included with Delphi EurekaLog is now reporting memory leaks in VCLTee.DBChart where no leaks were reported in XE3 The leaks are still evident even with a new project and a single TDBChart with three bar series connected to a TADOdataset using the TeeChart designer in the IDE with no code. Is there anything I can do about this, given that I have no access to the source code? The EurekaLog report: |Methods |Details|Stack |Address |Module |Offset |...

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...

Unable to deploy to iOS 7.1 device from Delphi XE5 Update 2
Hi, I am unable to deploy to iOS 7.1 device (iPhone 5) from Delphi XE5 Update 2. When pressing Run I am receiving the error: Local file cache for platform SDK "iPhoneOS 7.1" not found at C:\Users\ag30\Documents\RAD Studio\SDKs\iPhoneOS7.1.sdk. Would you like to update the platform SDK now? After pressing the Yes button I am receiving compiler error: " [Error] Error updating platform SDK "iPhoneOS7.1.sdk". Remote paths for this platform SDK has not been assigned" Thanks for any help, Asaf Asaf Goldman wrote: > Hi, > > I am unable to de...

Delphi XE Access violation in module 'dbxfb.dll' #2
Hi to all. I'm forced to migrate a Delphi 2007 application to Delphi XE using DbExpress and the dbxfb.dll driver. I had to make a trick for loading Blob fields into a TRichEdit. I got enforced to write this code: {code} procedure TForm1.LoadMemo(id: Integer); var I: Integer; strText: AnsiString; myStream: TMemoryStream; begin SQLQuery1.Close; SQLQuery1.Sql.Text := 'SELECT id, txt_field FROM my_table WHERE id = ' + IntToStr(id); SQLQuery1.Open; strText := SQLQuery1.FieldByName('txt_field').AsString; myStream := TMemoryStream...

Delphi 2010 Help Update and Delphi Updates 4 & 5
I installed Delphi 2010 Update 4 a few weeks ago. Is there a help update that corresponds with Delphi 2010 Update 4? If not where can I find the latest help update. How do I update help? > {quote:title=Bill Miller wrote:}{quote} > I installed Delphi 2010 Update 4 a few weeks ago. Is there a help update > that corresponds with Delphi 2010 Update 4? If not where can I find the > latest help update. How do I update help? The last help update for Delphi/C++ Builder 2010 was Help Update 1, released around the first of November 2009. It's available on the Embarcad...

ANN: Delphi Data Access Components with RAD Studio XE5 & Android support [Edit]
+Devart presents new versions of Delphi Data Access Components with support for Android application development in RAD Studio XE5. New versions of DACs have been significantly improved and they now provide numerous opportunities for more effective application development.+ The latest versions of Delphi Data Access Components contain the following new features : *RAD Studio XE5 support* With the newest RAD Studio XE5 support Devart users can develop their applications using the cutting-edge IDE for all the supported target-platforms: Win32, Win64, Mac OS, iOS, and now – Android. *...

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...

Does Delphi XE5 on Android work with the Android emulator? [Edit]
I find that even a hello-world app exactly like the one that David I outlines (add a button, one line of code, set button text) will not run on the Android Emulator configured out of the box. First, after installing the Rad Studio XE5 trial, I followed David I's steps exactly, and the emulator would not even start. Then I clicked Android SDK manager, updated it, and clicked run-without-debugging. It asked me if I wanted to start the emulator this time so I did. Now the Firemonkey app will not start up the emulator, and while it does appear to start debugging, the emulator scree...

Web resources about - ShowModal for Android Delphi XE5 Update 2, got access violation - embarcadero.delphi.firemonkey

Live extensions · chemerisuk/better-dom Wiki · GitHub
... : function () { var backdrop = DOM . create ( "div.modal-dlg-backdrop" ); // using bind to store reference to backdrop internally this . showModal ...

A Better 404 Page
... if (hostname.test(url) { suggestedLink.attr('href', url); suggestedLink.text(url); $('dialog .suggestion').html(suggestedLink); dialog.showModal(); ...

Quickstart Tutorial - Viggle
To get you started working with the Viggle VApp Javascript API we’ve put together this walk through of the functions you’re likely to want to ...

Best Vine Playlists - Vine Hash
... viewer that loops the funniest Vines so you can watch them on your computer or ipad. 0){window.location = site_url + 'favorite';}else{showM ...

wyoGuide: Dialogs and Panels
A guide, a tutorial for developing well-designed cross-platform applications


An In-Depth Introduction To Ember.js
... isolated view). Reusable Ember.js modals JavaScript tab The modalView is the default layout for all of our modals. It has two methods, showModal ...

Introducing Live Extensions For Better-DOM: What They Are And How They Work
... function() { var backdrop = DOM.create("div.modal-dlg-backdrop"); // using bind to store reference to backdrop internally this.showModal = ...

Making Modal Windows Better For Everyone
... document.getElementById('btnClose'); // to show our modal openModal.addEventListener( 'click', function( e ) { modal.show(); // or modal.showModal(); ...

Documentation - Viggle
... setLike setReminder setTitleBarImages setTitleBarTitle setTitleBarSubTitle setWebViewShouldScrollWhenReachingEnd showAd showModal whitelist ...

Resources last updated: 2/4/2016 1:17:49 AM