Programmatic Setting of Font Attributes in FireMonkey Controls

A peculiarity I’m noticing in FireMonkey…
Programmatic setting of Font attributes doesn’t work for certain controls, such as checkboxes, Labels, etc…
The following code generates a compiler error in the Rad Studio XE Trial...
CheckBox1.Font.Style:=[fsBold];
Label1.Font.Style:=[fsBold];
Strange that you can set the font attributes just fine through the Property Editor though!
Seems as though the scope/visibility of the font.style definition is incorrectly set in FireMonkey.
Could anyone running the full retail version of Delphi XE2 / RAD Studio XE2 verify if this issue is present there too please?

Dominique Willems wrote:
> Rudy Velthuis (TeamB) wrote:
> > Hmmm... if all enums are scoped anyway, they could have left off the
> > prefix:
> >
> > TFontStyle = (Bold, Italic, Underline, StrikeOut);
>
> I agree. Unless other enums inside the same unit use "Bold", of
> course.
Even then, it would make no difference, since if, say, there were an
enum
TTextStyle = (Bold, Italic, Underline, SmallCaps);
Then TFontStyle.Bold would not interfere with TTextStyle.Bold.
--
Rudy Velthuis
"Honolulu, it's got everything. Sand for the children, sun for
the wife, and sharks for the wife's mother." -- Ken Dodd.

0

Rudy

2/21/2011 5:42:45 PM

Jon Souter wrote:
> A peculiarity I’m noticing in FireMonkey…
>
> Programmatic setting of Font attributes doesn’t work for certain
> controls, such as checkboxes, Labels, etc…
>
> The following code generates a compiler error in the Rad Studio XE
> Trial...
>
> CheckBox1.Font.Style:=[fsBold];
> Label1.Font.Style:=[fsBold];
>
> Strange that you can set the font attributes just fine through the
> Property Editor though!
>
> Seems as though the scope/visibility of the font.style definition is
> incorrectly set in FireMonkey.
>
> Could anyone running the full retail version of Delphi XE2 / RAD
> Studio XE2 verify if this issue is present there too please?
This is because all enumerated types in the FireMonkey framework are
scoped.
ie. {$SCOPEDENUMS ON} is defined in each FMX unit.
Just prefix the enum value with the type.
ie. TFontStyle.fsBold

0

Jeremy

9/4/2011 1:28:58 PM

> CheckBox1.Font.Style:=[fsBold];
> Label1.Font.Style:=[fsBold];
The issue is that TFontStyle is now a scoped enumeration. For the VCL there
are mappings for backwards compatibility, but for FMX, you need to qualify
the elements with the type name:
CheckBox1.Font.Style:=[TFontStyle.fsBold];
Label1.Font.Style:=[TFontStyle.fsBold];
The same thing has been done for the MessageDlg enumerations. IMO, this
wasn't the greatest change ever made, since it can make code horribly
verbose, particularly when you're constructing a set of more than one
element.

0

Chris

9/4/2011 1:45:46 PM

Chris Rolliston wrote:
> > CheckBox1.Font.Style:=[fsBold];
> > Label1.Font.Style:=[fsBold];
>
> The issue is that TFontStyle is now a scoped enumeration. For the VCL
> there are mappings for backwards compatibility, but for FMX, you need
> to qualify the elements with the type name:
>
> CheckBox1.Font.Style:=[TFontStyle.fsBold];
> Label1.Font.Style:=[TFontStyle.fsBold];
>
> The same thing has been done for the MessageDlg enumerations.
Hmmm... if all enums are scoped anyway, they could have left off the
prefix:
TFontStyle = (Bold, Italic, Underline, StrikeOut);
--
Rudy Velthuis
"It may be necessary temporarily to accept a lesser evil, but
one must never label a necessary evil as good."
-- Margaret Mead

0

Rudy

9/4/2011 3:20:28 PM

Rudy Velthuis (TeamB) wrote:
> Hmmm... if all enums are scoped anyway, they could have left off the
> prefix:
>
> TFontStyle = (Bold, Italic, Underline, StrikeOut);
I agree. Unless other enums inside the same unit use "Bold", of course.

0

Dominique

9/4/2011 3:22:33 PM

> > TFontStyle = (Bold, Italic, Underline, StrikeOut);
>
> I agree. Unless other enums inside the same unit use "Bold", of course.
Why the caveat? The SCOPEDENUMS directive does two things: firstly, it
means you have to scope the elements in code (obviously), and secondly, it
removes the elements from the unit scope by making the type its own scope
below the unit (if that makes sense) -
{code}
unit MyUnit;
type
{$SCOPEDENUMS ON}
TScoped = (Bold, Italic);
TScopedToo = (Bold, Italic); //compiles, as elems not scoped to the unit
{$SCOPEDENUMS OFF}
TNotScoped = (Bold, Italic); //also compiles
TNotScopedToo = (Bold, Italic); //won't compile, as MyUnit.Bold and
//MyUnit.Italic already exist
{code}
Personally I wish it only did the second thing, making the explicit use of
the type name only necessary in cases of actual ambiguity.

0

Chris

9/4/2011 3:41:11 PM

Chris Rolliston wrote:
> Why the caveat?
Ooo, I was under the impression they were scoped to the unit, but they
are scoped to the type. Indeed, no caveat.

0

Dominique

9/4/2011 3:46:11 PM

Chris Rolliston wrote:
> Personally I wish it only did the second thing, making the explicit
> use of the type name only necessary in cases of actual ambiguity.
I agree. Is logical.

0

Dominique

9/4/2011 3:49:16 PM

> {quote:title=Dominique Willems wrote:}{quote}
> Rudy Velthuis (TeamB) wrote:
> > Hmmm... if all enums are scoped anyway, they could have left off the
> > prefix:
> >
> > TFontStyle = (Bold, Italic, Underline, StrikeOut);
>
> I agree. Unless other enums inside the same unit use "Bold", of course.
Thanks everyone for the comments and insight.
However, I have to say, that this just seems very strange to me. There is now an awkward distinction between the properties you can experiment with and assign at design-time in the IDE vs. those that you programmatically set during runtime.
e.g. fsBold's scope is visible to the FireMonkey IDE, so it seems counter-intuitive that you cannot also access this directly in code.
FireMonkey definitely has potential - I'll reserve my judgement until I've seen how the documentation evolves and how realistic it is for mere mortals like myself to produce our own FireMonkey Visual Components.

0

Jon

9/4/2011 3:57:38 PM

Rudy Velthuis (TeamB) wrote:
> Then TFontStyle.Bold would not interfere with TTextStyle.Bold.
<pat> <pat> <pat> It's Sunday and you are allowed to pull one. ;)

0

Dominique

9/4/2011 4:50:36 PM

Dominique Willems wrote:
> Rudy Velthuis (TeamB) wrote:
> > Then TFontStyle.Bold would not interfere with TTextStyle.Bold.
>
> <pat> <pat> <pat> It's Sunday and you are allowed to pull one. ;)
You replied to me, so I answered.
--
Rudy Velthuis
"Not only is there no God, but you try getting a plumber at
weekends." -- Woody Allen.

0

Rudy

9/4/2011 8:05:06 PM

Rudy Velthuis (TeamB) wrote:
> You replied to me, so I answered.
I know, I know.

0

Dominique

9/4/2011 9:13:57 PM

Thanks everyone for the comments and insight.
However, I have to say, that this just seems very strange to me. There is now an awkward distinction between the properties you can experiment with and assign at design-time in the IDE vs. those that you programmatically set during runtime.
e.g. fsBold's scope is visible to the FireMonkey IDE, so it seems counter-intuitive that you cannot also access this directly in code.

0

Jon

9/5/2011 11:55:39 AM

> {quote:title=Jon Souter wrote:}{quote}
> However, I have to say, that this just seems very strange to me. There is now an awkward distinction between the properties you can experiment with and assign at design-time in the IDE vs. those that you programmatically set during runtime.
You can set it programmatically at runtime. Just prefix the enumerator with the type scope.

0

Jason

9/6/2011 6:08:36 AM

> The same thing has been done for the MessageDlg enumerations. IMO, this
> wasn't the greatest change ever made, since it can make code horribly
> verbose, particularly when you're constructing a set of more than one
> element.
Yep, that also makes code particularly hard to follow by introducing
many redundant identifiers, and the same can be said for the uses
clauses with the unit prefixes (they should also have moved to a Java or
C++ style uses declaration, allowing multiple uses clauses, wildcards,
or at least changing the formatting style).
Eric

0

Eric

9/6/2011 8:01:38 AM

> > The same thing has been done for the MessageDlg enumerations. IMO, this
> > wasn't the greatest change ever made, since it can make code horribly
> > verbose, particularly when you're constructing a set of more than one
> > element.
>
> Yep, that also makes code particularly hard to follow by introducing
> many redundant identifiers, and the same can be said for the uses
> clauses with the unit prefixes
I'm a bit more OK with that, though I find the occasional double prefix
(Vcl.Imaging.Jpeg) and inconsistent casing (Vcl, Winapi - yuck! - FMX)
infuriating. The fact it also breaks code that fully qualified symbols in
the past is grating too.
> (they should also have moved to a Java or
> C++ style uses declaration, allowing multiple uses clauses, wildcards,
Maybe, but I'd start to worry about the compiler's symbol lookup speed in
such a case.

0

Chris

9/6/2011 8:12:43 AM

>> (they should also have moved to a Java or
>> C++ style uses declaration, allowing multiple uses clauses, wildcards,
>
> Maybe, but I'd start to worry about the compiler's symbol lookup speed in
> such a case.
Java & C# compiler seem to handle it just fine.
But mostly, without wildcards, having a "uses" clause formatted
vertically, with entries ordered by namespaces, and that can be hidden
in it own region, would clarify things a lot.
A moderately complex form's uses clause quickly looks like a huge
gibberish paragraph, it already did before prefixes, but with prefixes
it occurs even on simple forms.
Eric

0

Eric

9/6/2011 9:03:11 AM

Reply:

Similar Artilces:

Draw a vertical font in a Firemonkey controlhello to the community,
Excuse my newbie question but I'm looking for an easy way to draw vertical fonts in a FMX control.
I can't really use the rotation angle on the entire control, because it can contains horizontals and vertical fonts at the same time.
Also all controls are created and drawn on the fly with a Paint "override" procedure.
Actually may paint procedure works as expected for horizontal fonts and looks like:
{code}
procedure TmyControl.paint;
begin
// various init here
...
if Orientation = TOrientation.orHorizontal
then begin
...

Ann: FastReport FMX for Delphi XE3 (FireMonkey 2) and XE2 (FireMonkey) releasedDear friends,
Visual report designer is available now on both MS Windows and MAC OS X!
Full sources.
We can write here full list of possibilities, but it will so long. Let
see FastReport VCL and FastReport FMX comparison table:
http://www.fast-report.com/en/products/comparison-fast-report-firemonkey-vcl.html
And all of this - just now in your hands for business-applications for Mac.
Report generator FastReport FMX is the first multiplatform solution for
including Business Intelligence into software based on Embarcadero
FireMonkey IDE (Delphi for MS Windows and Apple Mac OS X)...

loop through controls to set attribute- was working.. now with new button on form... the attributes are not being set
I am only opening a new thread, because the old thread is old and I am not getting a response.
Please see old thread... http://forums.asp.net/t/1113116.aspx
Basically, I am setting a javacript on each textbox, to keep them from posting the form when you click the enter key.
The solution worked, however, since then I added dropdown and button before all the textboxes, in the form, and this button's job is to grab the data of previously posted forms and repopulate all the text fields on this massive form. Well, ever since I added this dropdown and new button, the loop to add the javascr...

Ann: X-platform report generator for Delphi XE3 (FireMonkey 2) and XE2 (FireMonkey) releasedDear friends,
Visual report designer is available now on both MS Windows and MAC OS X!
Full sources.
We can write here full list of possibilities, but it will so long. Let
see FastReport VCL and FastReport FMX comparison table:
http://www.fast-report.com/en/products/comparison-fast-report-firemonkey-vcl.html
And all of this - just now in your hands for business-applications for Mac.
Report generator FastReport FMX is the first multiplatform solution for
including Business Intelligence into software based on Embarcadero
FireMonkey IDE (Delphi for MS Windows and Apple Mac OS X)...

Help! loop through controls to set attribute- was working..Help! now with new button on form... the attributes are not being set
Hello.. I really need some help on this!
I am only opening a new thread, because the old thread is old and I am not getting a response.
Please see old thread... http://forums.asp.net/t/1113116.aspx
Basically, I am setting a javacript on each textbox, to keep them from posting the form when you click the enter key.
The solution worked, however, since then I added dropdown and button before all the textboxes, in the form, and this button's job is to grab the data of previously posted forms and repopulate all the text fields on this massive form. Well, ever since I added this dropdown...

FiremonkeyI am so dammed frustrated with firemonkey and livebindings.
The VCL + DB Controls were fast, consistent, and stable. This fmx
framework is crap. It's slow on my i5 Macbook. I'd be embarrassed to
put out an app like this. The help is lousy and apparently very few
people are using it based on my failed Google searches. I can see why.
Livebindings is cute when you have a few fields, but it a rats nest when
you have a moderately complex form and have to wire up dozens of
controls. There is no official support for nullable fields in
livebindings which blows my mind....

How to set font size and font style for a THotkey control?Now I add a Thotkey control on a form.Yes.It is a very useful control to handle hotkey.
But how I can set a bigger font and bold style for it.
Regards.
Jack Xiao
> {quote:title=bing xiao wrote:}{quote}
> Now I add a Thotkey control on a form.Yes.It is a very useful control to handle hotkey.
> But how I can set a bigger font and bold style for it.
The THotkey is simply a wrapper around the Windows HOTKEY control. It gets it's font size and style from the user's display settings, using one of the system values (see ComCtrls.pas, procedure TCustomHotKey.AdjustHeight f...

Installing components for FireMonkey HD and FireMonkey iOSHi,
How do I install components for both FireMonkey HD and FireMonkey iOS?
I have one package 'FMXMyFireMonkeyControl' and 'FMIFireMonkeyControl'
which both point to the same file with the same registration
'TFireMonkeyControl'.
If I compile one package (FMXMyFireMonkeyControl) it installs correctly,
then change the include file (FMCompile.INC) to compile for IOS
(FMIFireMonkeyControl) which is included in the
FMX.FireMonkeyControl.pas file:
{$I FMCOMPILE.INC}
uses
{$IFDEF COMPILEIOS}
FMX_Types, FMX_Objects, FMX_Forms, FMX_Dialogs, FMX_Effe...

Firemonkey font issuebeing new to Firemonkey
and starting to understand it.
everything is looking good - - what I design in the designer is showing
up when I run the program except - the text in numberboxs
always shows up as some small default size and font - -
yet it shows in designer as 20 point and Times Roman.
the labels and buttons all have the right font when running as in the
designer.
This can not be my code for the only code at this point is for the exit
button and a progress button that simply enables an animation only
any ideas?
thanks Jim P
maybe try a different front
lik...

Virtual Controls in FireMonkeyWhat are the fireMonkey controls that support UI virtualisation
> {quote:title=vikosh maha wrote:}{quote}
> What are the fireMonkey controls that support UI virtualisation
As of XE2 the TGrid is the only one I know of (certainly TListBox and TTreeView don't).
I haven't investigated XE3 far enough yet to give an answer.
...

setting non server control values: input type="text" how to set value programmatically?
<form id="someForm" runat="server" enableviewstate="true"> <input id="manualtextbox" type="text" value="abc" name="manualtextbox" /></form>
I have access to user supplied value via:
string userEnteredThisInForm = Request.Params["manualtextbox"]
but, how can I set the value when sending form back to browser?
If it's not runat="server" then you'll have to emit javascript to set the value:
document.getElementById('manualtextbox').value = '<desired value>';
add runat="sever" to the control
<input id="manualtextbox" type="text" value="abc" name="m...

with a theme set in a child page, setting attributes of a control in the master page don't work
I have noticed that if I dont't use a theme in a child page, the attributes such as bold, font-size, color of a control flow through from the Master Page.
For example, if I have a label in a master page that has attributes set, it will show correctly when linking with the child pages if I don't have a theme for the child page, if I do have a them set, it shows standard black text with a default font.
Any help would be very much appreicated.
well, in your theme you might be overwrinting styles, more specially, the stylesheet. And if you're using skind, same is...

set user control attributes
how can i put an user control in the specific place in page?
my pages in the browser have extra width and scrollbar. how can i remove this extra width and set a page fix in browser?
Cyrus sleep peacefully that we are awakesee all you want know about programminghttp://www.swg-co.comhttp://www.bpcyber.com
Hi,
It depends on page layout (flow or grid). You can set absolute positioning with grid layout, or use html elements to organize page in flow layout. Overflow style attribute affect scrollbar behavior of page.Leon LangleybenMCSD, ASP.NET MVPBlog...