Fixing a TForm.BorderIcons bug in FMX/OS X

If you try removing biMaximize from a FireMonkey form’s BorderIcons property, you’ll find the ‘maximise’ (zoom) button on OS X (i.e., the green ‘traffic light’) resolutely staying both visible and enabled. The reason for the bug is the following code in FMX.Platform.Mac.pas, and it exists in both XE2 and XE3:

        if TBorderIcon.biMaximize in AForm.BorderIcons then
          Style := Style or NSWindowZoomButton;              

The problem here is that NSWindowZoomButton is not a valid member of a Cocoa window style ‘set’, a fact the compiler wasn’t able to pick up given Objective-C does not have strongly typed sets like Pascal. Further, you cannot in fact hide or disable the zoom button via the window style – instead, you get a reference to the actual button and hide or disable it ‘directly’.

As Apple’s UI guidelines say to disable an unwanted zoom button rather than hide it, that’s what we’ll do for our fix. So, having taken a copy of FMX.Platform.Mac.pas (or if you’ve been following this blog before, with your latest version of it open), head to TCocoaPlatform.CreateWindow. Next, comment out the lines quoted above (i.e. ‘if TBorderIcon…’). Then, immediately after the NSWin.initWithContentRect call, add the following:

    if (Style and not NSResizableWindowMask <> 0) and
      not (TBorderIcon.biMaximize in AForm.BorderIcons) then

Setting the ‘target’ to nil is necessary, otherwise the Enabled property will get automatically re-enabled – roughly, you can think of the button as having had an action assigned to it when created, and setting the Target to nil as like setting the Action property to nil again.

8 thoughts on “Fixing a TForm.BorderIcons bug in FMX/OS X

  1. Looking forward to reading your next book, “Firemonkey without (too many) tears” by Chris Rolliston.

    Since you’re obviously digging into the framework with impressive vigour, can I ask if you’re producing usable apps with it, or is yours a more academic interest?

    I think I can probably guess most of what you’d say, but I’d be very interested to read your latest “Firemonkey report card”.


    • Ignoring little demos, I’m presently writing an application with it (‘an’ singular), however the approach I’m trying to take is to ignore issues with the framework that don’t block actual development until the end. While blogs posts like this one show I haven’t completely succeeded in that aim (ahem), I have in general kept to it.

      In terms of FireMonkey’s general usefulness, I think that depends on the context. If you’re writing something that is primarily custom drawn anyway, then the fact TMemo isn’t really fit for purpose and the tab control looks odd on OS X (for example) won’t matter much (though poor and/or inconsistent graphics performance might). Likewise, a CRUD application written in FMX might be acceptable when (as is usually the case for data entry programs) you aren’t selling (or answering) to the people who will be actually using the thing. Moreover, the main marketing claim – that you can target Windows and OS X from the same code – is a genuine one.

      While I haven’t exactly seen many cases, if you’d like to see an example of a fully-fledged, commercial FMX application, check out the OS X version of Giel Bremmers’ MulittrackStudio (there’s a free ‘Lite’ version):

      It fits into my first category, i.e. of something that is mostly custom drawn.

      • The problem is, take a look at “Ardour”, particularly clicking on the screenshot in the center of the page:

        That’s what you can do with gtk+ cross-platform, and gtk+ is open source and free with an LGPL license. It’s also been around 14 years, can target Linux, can be used with a variety of languages, and has almost as many core developers as the entire Delphi team.

        There’s a reason there’s nothing on Embarcadero’s website resembling a feature matrix comparing Delphi/Firemonkey with the competition or even any of the print targeting the competition. It’s like none of it exists. The question still remains why one should choose Firemonkey over the many, many other cross-platform solutions (with several such as GTK+, Qt and Mono/.Net being free and supporting more mainstream languages). I think in their hearts they know the only ones buying Delphi are previous owners of Delphi (even the full versions).

        I’d LOVE to have Marco give me an elevator pitch for Delphi and Firemonkey, but I don’t seem able to get anyone at Embarcadero to sell me on the current product. Even the CEO, in an interview with The Register, ducked the question of what Delphi offered that C# didn’t by saying that C# is .Net and Delphi wasn’t so C# “wasn’t a competitor” (Delphi might not compete with C#, but C# certainly competes with Delphi!). When the interviewer then brought up MS VSC++, the CEO swept that away as “not their focus”. When this is paired with Marco’s recent price comparison in which he decided not to mention any free/open source product because “their business models are different” and a comparison isn’t “fair and honest”, we’re left with a Delphi that essentially has no competition in their minds. It’s like being through the looking glass.

        Is there anything you would say to someone evaluating cross-platform alternatives today that you believe would sway them from more mainstream solutions and towards Delphi/FireMonkey?

        • Er, GTK+ looks completely alien on OS X. Given Apple’s previous form, I’d also be nervous of having to use a LGPL licence – that requires dynamic linking for anything not itself GPL, doesn’t it? Maybe Ardour is an exception – it would be useful to compare its look & feel with MultitrackStudio – but when I’ve just tried to download a demo version for OS X (no Windows version, huh?), I get a page with the lead developer’s photo on saying ‘no-cost’ downloads have been suspended. (For crying out loud, I only want the demo/trial version!)

  2. Pingback: Iniciar el 2013 con optimismo

  3. Pingback: Iniciar el 2013 con optimismo

  4. Pingback: Iniciar el 2013 con optimismo | Delphi Básico

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 )

Google photo

You are commenting using your Google 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