TheTired 0 Posted July 26, 2023 Is it possible to get current values of element in current style being use and to modify it? For example, of modify is if I wanted to be able to set windowborderstyle visible between true and false at runtime. Besides being able to read properties set could be useful for custom drawing. Share this post Link to post
Martifan 5 Posted July 30, 2023 Yes, it is possible to get and modify style properties of a control at runtime in Delphi. To get the current style being used by a control, you can use: StyleName: string; ... StyleName := Control.StyleName; This will give you the name of the active style. Then you can get the style object itself: Style: TStyle; ... Style := StyleServices.GetStyle(StyleName); Now you can read or modify any of the style properties. For example: // Read current value BorderVisible := Style.Properties['BorderVisible']; // Modify value Style.Properties['BorderVisible'] := not BorderVisible; The TStyle has a Properties dictionary that contains all the style elements. To apply the changes to the control, call: StyleServices.SetStyle(Control, Style); So in summary: Get active style name Get TStyle object Modify properties Apply changed style This allows you to dynamically tweak the visual styles at runtime. Share this post Link to post
TheTired 0 Posted August 1, 2023 Sorry, I forgot to mention I trying to do this for FMX. Share this post Link to post
Martifan 5 Posted August 2, 2023 FireMonkey, the cross-platform GUI framework used in Embarcadero's RAD Studio, doesn't include the same concept of styles as, say, CSS in web development. Instead, it uses style resources and style objects, which allow you to create and apply graphical properties to various UI elements. To access and modify the current style being used by an element at runtime, you'd typically need to: Access the style object of the control (this style object is basically a mini-component tree that's used to draw the control). Once you have the style object, you can find the element you're interested in and change its properties. For example, here's some simple code to change a button's text color at runtime: procedure TForm1.Button1Click(Sender: TObject); var TextObj: TText; begin TextObj := TText(Button1.FindStyleResource('text')); if Assigned(TextObj) then TextObj.FontColor := TAlphaColorRec.Red; // Change color to red end; As you can see, we're using FindStyleResource to get the 'text' style object (which is of type TText) for the button, and then we're changing its FontColor property. Keep in mind that the names of style objects ('text' in this case) depend on the style being used and the type of control. You'll need to look at the style in the IDE's style designer to know what names to use. As for a windowborderstyle visible property, I'm not sure if there's an equivalent in FireMonkey as it has a slightly different approach to how windows and borders are managed, compared to something like Windows Forms. You might be able to use the Form.BorderStyle property to control whether or not a form has a border, but this would typically be set at design-time, not runtime. It is possible to manipulate some aspects of the window appearance at runtime using platform-specific code, but it's not as straightforward or cross-platform as most FireMonkey code. The key idea in FireMonkey is that the appearance of controls is determined by style objects, not by properties of the control itself. If you want to change how a control looks or behaves in some way, you usually need to change the style, not the control Share this post Link to post
TheTired 0 Posted August 2, 2023 There is 'windowborderstyle' but using findStyleResource to find it returns nil. One method I can think of is to get current style resource change value and load style again. I was not sure if there was better approach. I have the styles loaded as resources I know how to modify them on Windows but multiple platform approach, I probably need to copy it to its own stream, change the value and set it. Share this post Link to post
Rollo62 536 Posted August 2, 2023 Doesn't the TextSettings property work for you ? https://docwiki.embarcadero.com/Libraries/Sydney/en/FMX.Graphics.TTextSettings Share this post Link to post
TheTired 0 Posted August 2, 2023 10 hours ago, Rollo62 said: Doesn't the TextSettings property work for you ? https://docwiki.embarcadero.com/Libraries/Sydney/en/FMX.Graphics.TTextSettings The form itself don't believe have that. The main thing I need to change is border style thing to be able to enable or disable the style. Share this post Link to post