Link to home
Start Free TrialLog in
Avatar of Member_2_7965240
Member_2_7965240

asked on

Delphi Anonymous ShowModal and Android problem

Hello,

I tried this : http://blog.marcocantu.com/blog/xe5_anonymous_showmodal_android.html

and my problem is that using this code:

var
  dlg: TForm1;
begin
  dlg := TForm1.Create(nil);
  // select current value, if avaialble 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);

Open in new window


The  dlg.DisposeOf; gives Access Violation error.
I tried it with Free, but that gives the same error message.

How can I free the form then? Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
disposing of an object (a form in this case) inside a method that way will always give Access Violation
if you would have put it after the showmodal method, it might have worked.