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>); begin if Supports(FWinService, IFMXModalWindowService) then ResultProc(ShowModal) else begin FResultProc := ResultProc; Show; end; end;
3. Amend TCommonCustomForm.SetModalResult to look something like this:
procedure TCommonCustomForm.SetModalResult(Value: TModalResult); begin FModalResult := Value; if Assigned(FResultProc) then begin Close; //!!!added FResultProc(FModalResult); FResultProc := nil; end; end;
4. Raise an exception in the classic ShowModal’s method body if IFMXModalWindowService isn’t implemented.