![]() ![]() Not to mention that your code above assumes the background colour is set as a solid colour. ![]() ![]() In either case you (or they) have to pour through the code and find and change the hard coded colour references. Or suppose somebody else uses your code but wants the ‘error’ colour to be red. Your controls will now look slightly wrong. What you’re doing is very tempting, but suppose you want to change the colour scheme in future, suppose the next version of windows uses a very pale grey for the background colour instead of white. The fact that component code relies on information in the style file in this way also raises the possibility that editing a style file could inadvertently block some component functionality. Style names seem to be assigned so that the component code can get access to style objects so maybe the intention was always there to expose either the background rectangle or its color as TEdit properties and they may appear in the future. Many objects in the style file do not and if you need to modify those objects you could apply your own style file assigning a style name to access the style object but that is not nearly so attractive. This only works because the background rectangle had a unique style name. T := AEditControl.FindStyleResource('background') Procedure SetEditControlColor(AEditControl: TCustomEdit AColor: TAlphaColor) ![]() Having obtained the correct (TRectangle) object it is possible to change the color property and repaint the component. Do not use the generic or you may end up changing the color of the wrong component. Fortunately the background rectangle of the TEdit style has a “style name” in the standard implementation which makes recovery of this object easy using the FindStyleResource method of the TEdit object. My solution consisted of finding the appropriate Style Object and changing the color value there. I have now produced a simple routine which achieves this function and in the process learnt a lot more about the style engine. When converting this code to FireMonkey I was unable to find a Color property for a TEdit Box. When a user puts unacceptable data into an edit box or fails to populate mandatory fields I like to be able to highlight these by changing the background to yellow. Some of the style parameters are also included in the object properties such as Font and FontFill (the new way to change the font color) but if the object code does not expose the parameter you need how do you change the style information dynamically at runtime? I came across this problem with a TEdit control. The new FireMonkey components have extensive design time functionality through the style engine so the presentation of components can be easily varied by the style editor. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |