TButton (or any FM component) publishing a color/bgcolor property?

I write till software, which requires all the buttons to be created at 
run time by reading XML configuration including colour, and background 
colour.

In VCL I just assign the forground colour (font.color) and background 
colour (self.color) on an RZButton.

How do I do a similar thing in FM ?

Seems that colours etc are attached only to a style, and cannot be 
attached directly to a visible component ?

Would I need to create a new style descendant for each and every button ?

Thanks.
0
Christopher
9/3/2011 7:08:34 PM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

11 Replies
1003 Views

Similar Articles

[PageSpeed] 8

The colors on individual buttons can be changed at runtime by using the FindStyleResource function.


procedure TForm4.Button1Click(Sender: TObject);
var
  r: TRectangle;
  t: TText;
begin

  r := Button1.FindStyleResource('myrectangle') as TRectangle;
  if Assigned(r) then
    r.Fill.Color := TAlphaColors.red;

  t := Button1.FindStyleResource('text') as TText;
  if Assigned(t) then
    t.Fill.Color := TAlphaColors.blue;

end;

The parts of the button you want to change have to have a StyleName assigned to them. The "myrectangle" and "text" are the StyleName of particular elements of the button. This is done in the style editor. Not all elements of the style have a StyleName, but they can be added in with the property editor.

I suppose you can do this for any style element of any FireMonkey control.
0
Douglas
9/4/2011 8:51:27 AM
On 4/09/2011 6:51 PM, Douglas Rudd wrote:
> The colors on individual buttons can be changed at runtime by using the FindStyleResource function.
>
>
> procedure TForm4.Button1Click(Sender: TObject);
> var
>    r: TRectangle;
>    t: TText;
> begin
>
>    r := Button1.FindStyleResource('myrectangle') as TRectangle;
>    if Assigned(r) then
>      r.Fill.Color := TAlphaColors.red;
>
>    t := Button1.FindStyleResource('text') as TText;
>    if Assigned(t) then
>      t.Fill.Color := TAlphaColors.blue;
>
> end;
>
> The parts of the button you want to change have to have a StyleName assigned to them. The "myrectangle" and "text" are the StyleName of particular elements of the button. This is done in the style editor. Not all elements of the style have a StyleName, but they can be added in with the property editor.
>
> I suppose you can do this for any style element of any FireMonkey control.

Would doing that not change the colours on all buttons with that style 
resource ?
0
Christopher
9/4/2011 12:16:01 PM
Christopher Burke wrote:

> On 4/09/2011 6:51 PM, Douglas Rudd wrote:
> > The colors on individual buttons can be changed at runtime by using
> > the FindStyleResource function.
> > 
> > 
> > procedure TForm4.Button1Click(Sender: TObject);
> > var
> >    r: TRectangle;
> >    t: TText;
> > begin
> > 
> >    r := Button1.FindStyleResource('myrectangle') as TRectangle;
> >    if Assigned(r) then
> >      r.Fill.Color := TAlphaColors.red;
> > 
> >    t := Button1.FindStyleResource('text') as TText;
> >    if Assigned(t) then
> >      t.Fill.Color := TAlphaColors.blue;
> > 
> > end;
> > 
> > The parts of the button you want to change have to have a StyleName
> > assigned to them. The "myrectangle" and "text" are the StyleName of
> > particular elements of the button. This is done in the style
> > editor. Not all elements of the style have a StyleName, but they
> > can be added in with the property editor.
> > 
> > I suppose you can do this for any style element of any FireMonkey
> > control.
> 
> Would doing that not change the colours on all buttons with that
> style resource ?

No, you are only changing the style for that button.

You will also need to make sure the color animation styles for the
button are updated, others the button will still have the default hover
and leave colors.
0
Jeremy
9/4/2011 1:41:18 PM
On 4/09/2011 11:41 PM, Jeremy North wrote:

> You will also need to make sure the color animation styles for the
> button are updated, others the button will still have the default hover
> and leave colors.

Cool thing about point of sale terminals ... they can't detect hover and 
leave :)
0
Christopher
9/4/2011 6:35:15 PM
> > > procedure TForm4.Button1Click(Sender: TObject);
> > > var
> > >    r: TRectangle;
> > >    t: TText;
> > > begin
> > > 
> > >    r := Button1.FindStyleResource('myrectangle') as TRectangle;
> > >    if Assigned(r) then
> > >      r.Fill.Color := TAlphaColors.red;
> > > 
> > >    t := Button1.FindStyleResource('text') as TText;
> > >    if Assigned(t) then
> > >      t.Fill.Color := TAlphaColors.blue;
> > > 
> > > end;


I had some trouble getting this to work when I wanted to change colour of a Tlabel - I ended up with this to make it go
{code}
Procedure SetTextColor(Lbl : Tlabel; c : Talphacolor);
var T: TFmxObject;
begin
 with Lbl do
 T := fmx.types.FindStyleResource('text');

 if (T <> nil) and (T is TText) then
 ttext(t).Fill.Color := c;
end;
{code}
0
Ralph
9/6/2011 10:45:13 PM
Wow!
If that is what it takes to change the background color of a fm label 
component then I'm disappointed. This looks like what we had to do back in 
the old days before the VCL. It looks like fm may be more akin to the 
original MFC (a thin wrapper around the windows api), rather than a rad 
tool. It must be easier than this! If not, then the next version must 
abstract these details away.

Dan

"Ralph Wesseling" wrote in message news:397465@forums.embarcadero.com...

> > > procedure TForm4.Button1Click(Sender: TObject);
> > > var
> > >    r: TRectangle;
> > >    t: TText;
> > > begin
> > >
> > >    r := Button1.FindStyleResource('myrectangle') as TRectangle;
> > >    if Assigned(r) then
> > >      r.Fill.Color := TAlphaColors.red;
> > >
> > >    t := Button1.FindStyleResource('text') as TText;
> > >    if Assigned(t) then
> > >      t.Fill.Color := TAlphaColors.blue;
> > >
> > > end;


I had some trouble getting this to work when I wanted to change colour of a 
Tlabel - I ended up with this to make it go
{code}
Procedure SetTextColor(Lbl : Tlabel; c : Talphacolor);
var T: TFmxObject;
begin
with Lbl do
T := fmx.types.FindStyleResource('text');

if (T <> nil) and (T is TText) then
ttext(t).Fill.Color := c;
end;
{code}
0
Daniel
9/6/2011 11:13:46 PM
> {quote:title=Daniel Sox wrote:}{quote}
> Wow!
> If that is what it takes to change the background color of a fm label 
> component then I'm disappointed. This looks like what we had to do back in 
> the old days before the VCL. It looks like fm may be more akin to the 
> original MFC (a thin wrapper around the windows api), rather than a rad 
> tool. It must be easier than this! If not, then the next version must 
> abstract these details away.
> 
> Dan


Well it gets worse - I have since found that some labels aren't changing colour - this is ridiculous. I need my label to be different colours depending on what the use has done - why has no one at embarcadero noticed that something this simple has become a mission to achieve - GRRRR!!!!!
0
Ralph
9/6/2011 11:17:01 PM
A long time ago circa 2000, I was working on a project with several other 
people. We were developing diagnostics for a big laser, we all had our own 
way of doing things and toolsets. The guy next to me was complaining he 
couldn't get the color of the text for a button to change. I showed him how 
I did it in Delphi, both at design and run time. Then I pointed out to him 
that with MFC he had to send a message to the button to change the text 
color! Seems like we may be taking a step back with fm.

Dan

"Ralph Wesseling" wrote

> Well it gets worse - I have since found that some labels aren't changing 
> colour - this is ridiculous. I need my label > to be different colours 
> depending on what the use has done - why has no one at embarcadero noticed 
> that
> something this simple has become a mission to achieve - GRRRR!!!!!
0
Daniel
9/6/2011 11:29:52 PM
> {quote:title=Ralph Wesseling wrote:}{quote}
> > {quote:title=Daniel Sox wrote:}{quote}
> > Wow!
> > If that is what it takes to change the background color of a fm label 
> > component then I'm disappointed. This looks like what we had to do back in 
> > the old days before the VCL. It looks like fm may be more akin to the 
> > original MFC (a thin wrapper around the windows api), rather than a rad 
> > tool. It must be easier than this! If not, then the next version must 
> > abstract these details away.
> > 
> > Dan
> 
> 
> Well it gets worse - I have since found that some labels aren't changing colour - this is ridiculous. I need my label to be different colours depending on what the use has done - why has no one at embarcadero noticed that something this simple has become a mission to achieve - GRRRR!!!!!

Try it with lbl.FindStyleResource('text') instead of using the default style. I guess using types.FindStyleResource gives you the default style.

Can't try it here.

Styles are a lot more powerful, but is very different to the (good) old days...
0
Jeremy
9/7/2011 1:33:22 AM
> {quote:title=Jeremy North wrote:}{quote}
> > {quote:title=Ralph Wesseling wrote:}{quote}
> > > {quote:title=Daniel Sox wrote:}{quote}
> > > Wow!
> > > If that is what it takes to change the background color of a fm label 
> > > component then I'm disappointed. This looks like what we had to do back in 
> > > the old days before the VCL. It looks like fm may be more akin to the 
> > > original MFC (a thin wrapper around the windows api), rather than a rad 
> > > tool. It must be easier than this! If not, then the next version must 
> > > abstract these details away.
> > > 
> > > Dan
> > 
> > 
> > Well it gets worse - I have since found that some labels aren't changing colour - this is ridiculous. I need my label to be different colours depending on what the use has done - why has no one at embarcadero noticed that something this simple has become a mission to achieve - GRRRR!!!!!
> 
> Try it with lbl.FindStyleResource('text') instead of using the default style. I guess using types.FindStyleResource gives you the default style.
> 
> Can't try it here.
> 
> Styles are a lot more powerful, but is very different to the (good) old days...

I have dropped using TLabel and gone for a primitive TText instead - that does see to work

I am trying to find a good tutorial for applying styles to entire app but then changing styles for certain components etc
0
Ralph
9/7/2011 2:23:42 AM
> {quote:title=Ralph Wesseling wrote:}{quote}
> > {quote:title=Jeremy North wrote:}{quote}
> > > {quote:title=Ralph Wesseling wrote:}{quote}
> > > > {quote:title=Daniel Sox wrote:}{quote}
> > > > Wow!
> > > > If that is what it takes to change the background color of a fm label 
> > > > component then I'm disappointed. This looks like what we had to do back in 
> > > > the old days before the VCL. It looks like fm may be more akin to the 
> > > > original MFC (a thin wrapper around the windows api), rather than a rad 
> > > > tool. It must be easier than this! If not, then the next version must 
> > > > abstract these details away.
> > > > 
> > > > Dan
> > > 
> > > 
> > > Well it gets worse - I have since found that some labels aren't changing colour - this is ridiculous. I need my label to be different colours depending on what the use has done - why has no one at embarcadero noticed that something this simple has become a mission to achieve - GRRRR!!!!!
> > 
> > Try it with lbl.FindStyleResource('text') instead of using the default style. I guess using types.FindStyleResource gives you the default style.
> > 
> > Can't try it here.
> > 
> > Styles are a lot more powerful, but is very different to the (good) old days...
> 
> I have dropped using TLabel and gone for a primitive TText instead - that does see to work
> 
> I am trying to find a good tutorial for applying styles to entire app but then changing styles for certain components etc

Create your style, using TStyleBook.
Assign the name of your style, to the stylecontrol (important) StyleLookup property

Not all controls support StyleLookup. They have to descend from TStyledControl from memory. 

From what I understand the "shapes" can't be styled because they are used to create the styles.
0
Jeremy
9/7/2011 3:48:15 AM
Reply:

Similar Artilces:

Generic components with published properties.
If I write button that has a generic property, then install it into Delphi, the published properties that are generic won't appear in the object inspector. TGenericButton<T> = class(TButton) private FASomething: T; FAnInteger: Integer; published property AnInteger: Integer read FAnInteger write FAnInteger; property ASomething: T read FASomething write FASomething; end; TIntegerButton = class(TGenericButton<Integer>) end; procedure Register; implementation procedure Register; begin RegisterComponents('My Generic ...

published property for a handle to another component
Hello, Can someone tell me the proper way to create a published property in a custom component which references a handle to another component such as a TForm, or some type of TControl? What I have been doing in the past was just creating a published property of type TControl *. However, this has created some issues because of the order of creation and deletion of components. I remember Remy saying that this should not be done in this way, but instead using the name of the component. So, if I use the name of the component, then how do I get the property editor to list string names of c...

Color problems with components in Delphi 2009?
Hi list ~ just wrote a little visual component that is made up from a few multi-colored panels. At design time the colors show nicely and also when I use the component in a non-themed application. In a themed application ('Use Themes' checkbox checked) the entire components loses its colors and turns clBtnFace. Anybody have an idea what's up? TIA Kai > {quote:title=Kai Peters wrote:}{quote} > Hi list ~ > > just wrote a little visual component that is made up from a few multi-colored panels. At design time the colors show nicely and also when I use th...

Editing PB Component Properties adds com.sybase.jaguar.component.iso_level property
Whenever we use Jaguar Manager (EAS 4.2.2) to set a component property on a PowerBuilder component the following property is appended automatically: com.sybase.jaguar.component.iso_level=serializable From what I read on a Sybase document the property creates problems. Anyone experiencing this? TIA A. This is a multi-part message in MIME format. --------------090406010200000407040509 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Aggelos Paraskevopoulos wrote: > Whenever we use Jaguar Manager (EAS 4.2.2) to set a component ...

Component Properties All Properties tab
Is there a size/item limit to the Component Properties All Properties repository? I'd like to store (potentially hundreds) customer connection username/password information in this area. None we are aware of. Dave Wolf Internet Applications Division "David Short" <david.short@prescriber.com> wrote in message news:396A581C.2454F1DB@prescriber.com... > Is there a size/item limit to the Component Properties All Properties > repository? I'd like to store (potentially hundreds) customer > connection username/password information in this area. >...

How to read Component Property (from the component itself)
I am using this code to read a Jaguar Component Property (from the Component itself) : private String getProperty(String _s) throws javax.ejb.EJBException, com.sybase.jaguar.util.JException { String propVal = null; try { powersoft.powerj.jaguar.InitialContext ctx = new powersoft.powerj.jaguar.InitialContext (); propVal = (String)ctx.lookup(_s); } catch (java.lang.Exception e) { com.sybase.jaguar.server.Jaguar.writeLog(true, getClass().toString() + e.toString()); } return (propVal); } ...

2010 Components with bad color property [Edit]
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_36498.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" After upgrade to C Builder 2010, the Color property of these components changed type to an integer in the property editor. They work normally in version 2007. Edited by: Rodney Whitehouse on Mar 15, 2010 9:18 AM --JivePart=_36498.zeB8CwDOH5aMJzMl-- > {quote:title=Rodney Whitehouse wrote:}{quote} > After upgrade to C Builder 2010, the Color property of...

Delphi VCL components properties history articles
Hi, i would like to know where i can found Delphi VCL components properties history information because i need to know from wich Delphi version a property exists or from wich version a protected procedure was marcked with "virtual" command from a standard component. Thanks, Maurício "Julio Pião" <=?Utf-8?Q?Julio_Pi=C3=A3o?=> wrote in message news:292952@forums.embarcadero.com... > i would like to know where i can found Delphi VCL components > properties history information AFAIK, that kind of list does not exist anywhere. > i ...

Delphi 2010 Component Colors In Design Mode
In Delphi 2010, I'm finding that some components, particularly TDBGrids, do not display their color property while in design mode, but display properly when executing. Is there yet another setting I'm missing? Thanks Al Wimberly wrote: > In Delphi 2010, I'm finding that some components, particularly > TDBGrids, do not display their color property while in design mode, > but display properly when executing. Is there yet another setting I'm > missing? No. I think this can happen if you disable theme support for your applications, since the IDE itsel...

.net component to Delphi component ?
Hello, Is there a way to use .net component inside Delphi ? Thanks On Tue, 18 Nov 2008 13:16:37 -0800, isaac sam wrote: > Is there a way to use .net component inside Delphi ? http://www.managed-vcl.com/ has some libraries for this. -- Marc Rohloff [TeamB] marc -at- marc rohloff -dot- com Marc Rohloff wrote: > On Tue, 18 Nov 2008 13:16:37 -0800, isaac sam wrote: > >> Is there a way to use .net component inside Delphi ? > > http://www.managed-vcl.com/ has some libraries for this. > I was hoping for a free tool but thanks On Tue, 18 Nov 2008...

Published properties and property editor... how to?
+Sorry if these questios are already answered.... i'm pretty sure i've seen somewhat related but after 40 mins of searching i'm unable to find it.+ Working with BDS2006 I have a component, derived from another not developed by me, that need to show some properties in the Inspector. They are: - FONT (the standard Font thing: the ancestor does not have this property, and basically i need to "expose" the Font of a TLabel. 2 pictures ("OnPicture" and "OffPicture"). I'm just unable to make these properties appears in the Object inspector, and ...

ASP.NET-How to create [User Control], whose properties is color, and we can chose its color in panel of properties?
Im a beginner in Asp.net, and I have met many difficulties (perhaps all of they is fundamental )! Plz !!!!!! You can add a public property for the color and access it in the code-behind. However properties won’t appear in the designer for User Controls (at least I haven't found a way yet). They will for custom server controls.Brian PriceCo-Author of UCanUse ProductsUCanUse.comWittysoft, LLC Yeah adding a public property is not enought for user control ! this called "the color picker drop-down list". I think it is very fundamental, but i don't know where I can find document ...

Delphi / FireMonkey release components created at runtime [Edit]
Hello, XE6, Win7 Am I right I thinking that if I create a component, such as TImage, at runtime, Delphi automatically releases the memory when the program closes. I declared this: im: TImage; as a TForm variable. Put this in .FormCreate: ReportMemoryLeaksOnShutdown := DebugHook <> 0; This picks up things like TStrokeBrush when I don't run .Free; I then put this in: procedure TFrmScales.Button4Click(Sender: TObject); begin im := TImage.Create(self); im.Bitmap.Assign(I_note.Bitmap); // I_note is a TImage that I put there at design-time im.Pa...

Why does the Color published property of a my own BitBtn does not change with the value setting
Hello, I want to have the Color property on my custom BitBtn to change it value according to some state of my application. I'm already published it but the color is not change with the value that I set to it, and always show clBtnFace. Following is the code that I'm using. Could you help me please? cpp file ------- __fastcall TBitBtn_MesaRestaurante::TBitBtn_MesaRestaurante(TComponent* Owner) : TBitBtn(Owner) { Color = clSkyBlue; } h file ----- class PACKAGE TBitBtn_MesaRestaurante : public TBitBtn { private: protected: public: __published: __proper...

Web resources about - TButton (or any FM component) publishing a color/bgcolor property? - embarcadero.delphi.firemonkey

Publishing - Wikipedia, the free encyclopedia
Publishing is the process of production and dissemination of literature , music , or information — the activity of making information available ...

Publishing - Wikipedia, the free encyclopedia
Publishing is the process of production and dissemination of literature , music , or information — the activity of making information available ...

Bupa goes after millionaire surgeons by publishing surgery prices
... surgery costs to put pressure on fee-gouging surgeons and help customers avoid shock out-of-pocket costs. Health fund Bupa will start publishing ...

10 Tips for Publishing Videos on Facebook
... library: Speaking of controlling the audience for videos, page admins can take steps including the prohibition of third-party embeds, publishing ...

Bupa goes after millionaire surgeons by publishing surgery prices
... surgery costs to put pressure on fee-gouging surgeons and help customers avoid shock out-of-pocket costs. Health fund Bupa will start publishing ...

Answers to Your Publishing Questions
... give answers, or state what they want to learn or improve with their writing. Last week's thread included a call for questions about publishing, ...

"The 2015 Man Booker prize winner Marlon James has slammed the publishing world, saying authors of colour ...
"... and that he could have been published more often if he had written 'middle-style prose and private ennui.'" At a sold-out Guardian event ...

Meet the 19-year-old whose 80-person company is taking the fashion, film, and publishing worlds by storm ...
Tavi Gevinson is not your typical 19-year-old. She's edited four books, starred in a Broadway show, and leads a staff of 80 at Rookie, an online ...

Downtown Music Publishing and Pandora Sign Licensing Agreement Continuing Pandora’s Advancements Into ...
Pandora (NYSE:P), the world's most powerful music discovery platform, and Downtown Music Publishing, the leading music rights management company ...

German publishing giant sues dev behind iOS 9 ad blocker
Begun, the iOS 9 ad blockers legal wars has. Germany’s Axel Springer, a company which owns major newspapers like Bild and Die Welt, is trying ...

Resources last updated: 12/24/2015 2:29:34 AM