Talk:Using FireMonkey Modal Dialog Boxes

From RAD Studio
Jump to: navigation, search

Yes, I use the same code. Please not that the exception occurs only when you run the app under debugger control. I copied my source code and debug executable here [1]. I'm running on Win7/64 fully updated. 16GB of memory and dual quad core Xeon processors (HP Z600 Workstation). XE5 Version 19.0.14356.6604


Second Code Snippet cause an access violation at program exit (On Windows) using Delphi XE5 Update 2.

Hmm… I cannot reproduce it.
I created a FireMonkey Desktop Application - Delphi and added a second form to it. In the first form I have a TButton and a TEdit, while in the second form I have a TListBox. With the following code, I can start the application, press the button, close the dialog box, close the application, and I never get an access violation. These are the sources of the units I used:
  • Unit1.pas
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.Button1Click(Sender: TObject);
var
  dlg: TForm2;
begin
  dlg := TForm2.Create(nil);
  // select current value, if available in the list
  dlg.ListBox1.ItemIndex := dlg.ListBox1.Items.IndexOf(Edit1.Text);

  dlg.ShowModal(procedure(ModalResult: TModalResult)
    begin
      if ModalResult = mrOK then
      // if OK was pressed and an item is selected, pick it
      if dlg.ListBox1.ItemIndex >= 0 then
        Edit1.Text := dlg.ListBox1.Items [dlg.ListBox1.ItemIndex];
      dlg.DisposeOf;
    end);
end;

end.
  • Unit2.pas
unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    ListBox1: TListBox;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.fmx}

end.
Could you please check whether or not it works for you using the same code I used? — Adrian Chaves Need help? 00:50, 20 December 2013 (PST)