FMX/XE5 issue: new ShowModal overload poorly implemented

A few weeks ago Marco Cantù, the Delphi Project Manager, blogged about a new FMX ShowModal overload introduced in XE5. As Marco explained, the reason for this new overload is because a Windows-style ShowModal isn’t possible on mobile platforms. While his blog post met the odd objection in the comments, if anything, a revised ShowModal could have been added from the start – due to deliberate design decisions by Apple, the classic ShowModal isn’t entirely straightforward even on OS X, so Embarcadero have my sympathies.

That said, I’ve found the actual implementation of the new overload problematic. On Windows and OS X, it fails to show the form modally at all (see QC 120024). Moreover, on all platforms, setting the shown form’s ModalResult property (either directly or by setting a button’s ModalResult property) does not close the form like it would do in the classic ShowModal style (QC 120025). To fix these issues, I would suggest Embarcadero do something like the following:

1. Move the ShowWindowModal method from IFMXWindowService into its own IFMXModalWindowService interface. If a platform doesn’t implement classic ShowModal functionality, then it shouldn’t implement the new interface.

2. Change the new ShowModal overload’s implementation to call the classic ShowModal if it is supported:

procedure TCommonCustomForm.ShowModal(const ResultProc: TProc<TModalResult>);
  if Supports(FWinService, IFMXModalWindowService) then
    FResultProc := ResultProc;

3. Amend TCommonCustomForm.SetModalResult to look something like this:

procedure TCommonCustomForm.SetModalResult(Value: TModalResult);
  FModalResult := Value;
  if Assigned(FResultProc) then
    Close; //!!!added
    FResultProc := nil;

4. Raise an exception in the classic ShowModal’s method body if IFMXModalWindowService isn’t implemented.

One thought on “FMX/XE5 issue: new ShowModal overload poorly implemented

  1. Pingback: Te Waka o Pascal · Platform Ignorants

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s