Changing style properties at run-time [Edit]

I'm playing around with a FMX app for the first time, and I'm trying to do something really simple:

{code}
  panel1.Color := clBlue;
{code}

After searching around using Google, on the discussion boards here, and elsewhere, all I've found is how to create a new style for every freaking possible combination of styles that you'd ever want and switch between them at run-time, and a tutorial on how to build a parser that searches through .style files and uses RTTI to use dynamic casting to look-up and change property values at run-time.

Can somebody please show me a simple one-line equivalent for changing visual properties like this in FMX?

Is it even possible to do in one line under FMX?

I've even found tutorials that talk all about 3D and fancy schmancy visual stuff, yet not one example of setting simple properties like a panel's color, or a font's size and style at run-time. I do these a LOT in my code, and I hope you don't have to load a parser up with your run-time units in order to parse .style files just to lookup and change a few simple properties like this!

-David

PS: is there a tutorial anywhere that talks about how to do simple stuff like this at run-time?  All of Embarcadero's tutorials that I can find highlight design-time style settings and fancy run-time stuff like alpha-blending, animations, and rotating things in 2D and 3D spaces.  Where are the basics covered?
0
David
7/7/2013 4:53:33 AM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

2 Replies
3274 Views

Similar Articles

[PageSpeed] 17

> {quote:title=David Schwartz wrote:}{quote}
> Can somebody please show me a simple one-line equivalent for changing visual properties like this in FMX?

You can use FindStyleResource to fetch an individual item from a style. If you really insist on a single line:

(Panel1.FindStyleResource('background') as TRectangle).Fill.Color := claRed;

You'll do best to pop that code in the OnStyleLookup event handler.

If you want to do this regularly I'd advise creating a custom component, add a FillColor property and override ApplyStyle.

Changing fonts is much easier (for most controls): set the Font property and update the StyledSettings property to reflect what you are modifying.

--
FireMonkey users guide http://bit.ly/10abRZX
MonkeyStyler FireMonkey style designer http://bit.ly/PzxKyI
Embarcadero MVP
0
Mike
7/9/2013 6:30:26 PM
> {quote:title=David Schwartz wrote:}{quote}
> I'm playing around with a FMX app for the first time, and I'm trying to do something really simple:
> 
> {code}
>   panel1.Color := clBlue;
> {code}
> 

You could just use the TRectangle component instead. 

{code}
  Rectangle1.Fill.Color := TAlphaColorRec.Blue;
{code}

or

{code}
  Rectangle1.Fill.Color := claBlue;
{code}

claBlue is declared in System.UIConsts.
TAlphaColorRec is declared in System.UITypes.

FireMonkey is different and takes some learning. If you have access to the source it is a good place to start.

You can change the border attributes of the rectangle by setting the "Stroke" properties.

To work with styles at runtime, you either need to override the ApplyStyle for your custom control, or create an OnStyleLookup event handler. This event is called once the style information has been loaded by the control. Trying to access style information outside of the OnStyleLookup event, may result in failure due to the style not being fully loaded yet.

If you look at the style for a TPanel, it is just a TRectangle. Generally you can use just TRectangle and not have the overhead of a TPanel. However, using a TPanel does give flexibility in further customising the appearance of it. You could add labels, buttons and any other controls to the style and have that display on the panel as well.

I would suggest if you are finding holes in the documentation, then others are as well. Perhaps type up the questions you have and send them to the Developer Relations guys (Anders, David I) and see if they can get some of the questions answered officially. Otherwise post here and someone will hopefully provide a suitable answer.
0
Jeremy
7/10/2013 12:28:17 AM
Reply:

Web resources about - Changing style properties at run-time [Edit] - embarcadero.delphi.firemonkey

General Growth Properties - Wikipedia, the free encyclopedia
Chicago , Illinois , U.S. General Growth Properties, Inc. is an American real estate investment trust , headquartered at 110 North Wacker Drive ...

RentalRoost Brings Facebook Into Process Of Matching Up Home Seekers, Available Properties
... places to live , as RentalRoost , a San Francisco Bay-area-based website that incorporates Facebook data into its rankings of available properties, ...

Extended Profile Properties - Facebook-Entwickler
These Permissions cannot be revoked in the Login Dialog during the login flow, meaning they are non-optional for Users when logging into your ...

PortPerry Properties (@brian14mckinlay) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Hawaii Real Estate Properties for iPad on the App Store on iTunes
Get Hawaii Real Estate Properties for iPad on the App Store. See screenshots and ratings, and read customer reviews.

Airbnb's reach extends from spare rooms to empty, multi-room properties, report reveals
Nearly half the listings on Airbnb in Melbourne are not for spare rooms in someone's home but for entire houses or apartments that are never ...

Australian Federal Police raid properties in new CFMEU-linked investigation
Federal Police have raided properties as part of an investigation into a CFMEU organiser suspected by authorities of being bribed.

ATO crackdown on rental properties, holiday homes
Australians who rent out their holiday homes for a few weeks a year, but then try to claim bigger deductions - including maintenance and mortgage ...

Digital detox: Australians seek out nature properties to overcome technology burnout
Holiday home rental companies say they have seen a spike in the number of customers seeking digital detoxes, allowing savvy homeowners to offer ...

These are the 9 Airbnb properties where everybody dreams of staying
Airbnb has become popular partly because people can open up their exquisite (or strange) properties around the world. When Airbnb looked at ...

Resources last updated: 1/23/2016 4:46:47 AM