Is there an FMX bug in TCanvas between platforms.

I may have uncovered a bug in FMX use of painting on TCanvas.  It does not appear in android applications, but the bug shows up in Windows versions of the same app.

I have put both a FMX TPanel and a nested FMX TImage  on my form such that all the centers are co-located.  Below this I have an FMX button.   I then created an OnPaint event that contains Paths that outline the panel and also the image  as well as an if statement that draws a diagonal line across the Image if the button has been pushed..   The button's OnClick event calls the OnPaint event.

When the form is created, the system automatically calls the OnPaint.  In both the windows app and the android app, all goes as expected: the panel and the image are outlined.  But when the button is pushed in the android version, the result is as expected:  both the panel and the image are outlined, they remain nested in the center of the form, and a diagonal is drawn across the image.  However, in the windows version of the app with the same code,  the clicking the button results in All Canvases' origin reverting back to the Form's origin, the upper left corner of the form. 

A second bug, or perhaps just a difference in how windows processes FMX OnPaint events,  the lines draw in windows persist, while in android, the canvas seems to be erased upon beginning an OnPaint.

I am using C++ Builder 10.3 Community Edition on a Windows 10 machine.

Can anyone tell me if this is normal or is this a bug in FireMonkey?

Note: I asked a question related to this about a week ago that shows kind of the result in windows but with slightly different code .   SeeTPaintBox Canvas Problems in FMX


  • Never call an OnPaint event handler from code directly. Instead invalidate the control(s) in question and let the system fire the event. This way the relevant canvases are set up correctly. You need to store the information you need to know what to draw (in your case a state flag that tells the drawing code that the button has been pressed) before invalidating the control.

    I don't know how this is handled in FMX or other platforms (i'm a Windows-only programmer using the VCL), but in the VCL a control's canvas is just an interface for the system drawing functions that operate on the part of the screen the control is shown on. The canvas has no data storage of its own, unlike the canvas of a bitmap or metafile.