问题
We are working with Firemonkey since version 1, and still find difficulties updating components that are currently visible on the screen. There are many 'ways' to request a repaint in Firemonkey, perhaps too many:
- Applying a style (ApplyStyle event) - mostly when it becomes visible on screen
- Requesting ".repaint" - some components have this
- Requesting ".realign" - sometime works, current versions of FMX seem to drop / hide it
- Requesting ".invalidate" - some components, mostly forms, have this
- Requesting ".invalidateRect" - most components have this
- Calling the ApplyStyle event manually - not guaranteed to work and design-wise is incorrect...
Given the lacking documentation for the platform, is there a "well defined" way to change the visual appearance (internal values of a style) when a component is already displayed? I.e. a listboxItem that is already present and visible on screen, a TGrid cell, and so on. Would appreciate your thoughts...
回答1:
I don't think there's a single unified 'correct way' to refresh the visual of components in Firemonkey.
However, as a recommendation from personal experience, I'd take the .repaint
route - this method is at the TControl
level, and so it precedes primitives and styled controls (which are generally made up of primitives) and so applies to all visual controls. It also doesn't require parameters, so it's a good all-round solution.
I have noted that Firemonkey has always had an issue correctly repainting controls of it's own accord. Often I'm left with a 'shadow' of the previous visual of a control/primitive, and must call .repaint
manually to update it. This got noticeably worse with FM2 and FM3 (presumably due to optimizations made for mobile platforms), and so doing a manual .repaint
-- especially where effects such as TGlow
and moving or rotating controls/primitives are concerned, has become a standard practice for me.
来源:https://stackoverflow.com/questions/18074417/firemonkey-updating-visual-components