Board index » cppbuilder » Change the Font with code

Change the Font with code


2008-02-08 01:41:13 AM
cppbuilder51
Hi All,
I want to change the Font of a TEdit Component in my code.
There are many of these TEdit's in the form of a 9x9 grid (sudoku) and I
want to distinguish between
entries, I have changed the Color of the EditControls (of the TEdit
components) as follows
EditControls[Row][Col]->Color = clGray; // OK
But if I try the following to change the Font or Style
EditControls[Row][Col]->Font->Style->fsItalic = true;
Or
EditControls[Row][Col]->Font->Style = fsItalic;
then I get the following error messages for each attempt
E2288 Pointer to structure required on left side of ->or ->*
Or
E2034 Cannot convert 'TFontStyle' to 'TFontStyles'
I have tried to change the Font in a similar way using a Font name that is
shown in the Object Inspector
for that TEdit but with the same error messages as above.
Hope some one can guide me.
Thanks Penny.
 
 

Re:Change the Font with code

"Penny hapeny" < XXXX@XXXXX.COM >wrote in message
Quote
But if I try the following to change the Font or Style

EditControls[Row][Col]->Font->Style->fsItalic = true;
Or
EditControls[Row][Col]->Font->Style = fsItalic;

then I get the following error messages for each attempt
That is not the correct way to use the Style property. You need to use the
'<<' and '>>' operators instead in order to enable/disable individual
values, ie:
// enable fsItalic
EditControls[Row][Col]->Font->Style =
EditControls[Row][Col]->Font->Style << fsItalic;
// remove fsItalic
EditControls[Row][Col]->Font->Style =
EditControls[Row][Col]->Font->Style>>fsItalic;
If you just want to enable fsItalic and remove all other styles, then you
can do this instead:
EditControls[Row][Col]->Font->Style = TFontStyles() << fsItalic;
Gambit
 

Re:Change the Font with code

Hi Gambit,
Thanks for your reply, if I try to change the Font->Name in the same way as
follows
EditControls[Row][Col]->Font->Name << Courier;
I get the following error message
//[C++ Error] Unit_036_cpp.cpp(1026): E2451 Undefined symbol 'Courier'
I wonder what I am doing wrong here
Thanks
Penny
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Penny hapeny" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>But if I try the following to change the Font or Style
>
>EditControls[Row][Col]->Font->Style->fsItalic = true;
>Or
>EditControls[Row][Col]->Font->Style = fsItalic;
>
>then I get the following error messages for each attempt

That is not the correct way to use the Style property. You need to use
the '<<' and '>>' operators instead in order to enable/disable individual
values, ie:

// enable fsItalic
EditControls[Row][Col]->Font->Style =
EditControls[Row][Col]->Font->Style << fsItalic;

// remove fsItalic
EditControls[Row][Col]->Font->Style =
EditControls[Row][Col]->Font->Style>>fsItalic;

If you just want to enable fsItalic and remove all other styles, then you
can do this instead:

EditControls[Row][Col]->Font->Style = TFontStyles() << fsItalic;


Gambit

 

{smallsort}

Re:Change the Font with code

Hi Penny
Penny hapeny says:
Quote
Hi Gambit,

Thanks for your reply, if I try to change the Font->Name in the same way as
follows

EditControls[Row][Col]->Font->Name << Courier;
It is only when the property is a Set You have to use <<
Font->Name is of AnsiString type
So You just have to do like any other AnsiString
EditControls[Row][Col]->Font->Name = "Courier";
EditControls[Row][Col]->Font->Color = clBlue;
EditControls[Row][Col]->Font->Pitch = fpFixed;
EditControls[Row][Col]->Font->Size = 10;
EditControls[Row][Col]->Font->Style = TFontStyles() << fsBold << fsItalic;
Kind regards
Asger
 

Re:Change the Font with code

Many thanks Asger,
That works fine. How do you know what Properties are set, and others are as
I have used till now.
Thanks
Penny
.
"Asger Joergensen" < XXXX@XXXXX.COM >wrote in message
Quote

Hi Penny

Penny hapeny says:
>Hi Gambit,
>
>Thanks for your reply, if I try to change the Font->Name in the same way
>as
>follows
>
>EditControls[Row][Col]->Font->Name << Courier;

It is only when the property is a Set You have to use <<
Font->Name is of AnsiString type

So You just have to do like any other AnsiString

EditControls[Row][Col]->Font->Name = "Courier";

EditControls[Row][Col]->Font->Color = clBlue;
EditControls[Row][Col]->Font->Pitch = fpFixed;
EditControls[Row][Col]->Font->Size = 10;
EditControls[Row][Col]->Font->Style = TFontStyles() << fsBold << fsItalic;

Kind regards
Asger
 

Re:Change the Font with code

"Penny hapeny" < XXXX@XXXXX.COM >wrote in message
Quote
EditControls[Row][Col]->Font->Name << Courier;

I get the following error message
//[C++ Error] Unit_036_cpp.cpp(1026): E2451 Undefined symbol 'Courier'
The Name property is an AnsiString. Also, the '<<' and '>>' operators only
apply to Set-based properties specifically. For everything else, use the
'=' operator normally instead, ie:
EditControls[Row][Col]->Font->Name = "Courier";
Gambit
 

Re:Change the Font with code

"Penny hapeny" < XXXX@XXXXX.COM >wrote in message
Quote
How do you know what Properties are set
Read the documentation.
Gambit
 

Re:Change the Font with code

Hi Gambit,
Thanks for your replies.
You say here read the documentation. With my purchase of Builder 6 standard
edition I only received a small book called Quick Start C++ Builder,
this doesn't make any mention of Set's. The program Help when looking for
set or Set doesn't produce anything related to this issue.
I have a book called Teach Yourself Borland C++ Builder 4 in 24 Hours By
Kent Reisdorph. From your post I have looked in this under Set
and found the following. One feature that Pascal has, but C++ doesn't, is
the set. Borland decided to implement sets in the form of a template class.
Sets are used frequently throughout the VCL.
For an example, he then goes on to describe how to use it to add attributes
to the font style, and gives code examples similar to yours and Asger's. But
doesn't mention any other properties that use Sets.
In the Program help from your example I have looked for TFontStyles() and
this has shown me an example similar to yours.
I wonder what other properties are similar to this. Its only with yours and
Asger's helpful post that has lead me on this route, and I
wonder if I would have ever got there without this News Group
I look forward to your comments.
Penny
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Penny hapeny" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>How do you know what Properties are set

Read the documentation.


Gambit

 

Re:Change the Font with code

Hi Penny
Penny hapeny says:
Quote
Hi Gambit,

Thanks for your replies.
You say here read the documentation. With my purchase of Builder 6 standard
edition I only received a small book called Quick Start C++ Builder,
this doesn't make any mention of Set's. The program Help when looking for
set or Set doesn't produce anything related to this issue.
I only have BCB5 pro, but I would expect that Builder 6 standard
also have help files included if not I think they can be downloaded
from CodeGear.com.
In my BCB5 they are installed in:
CBuilder5\Help
and the helpfile in question is probably called:
bcb6vcl.hlp (mine is bcb5vcl.hlp)
If the help is installed it should be possible for You
to position the cursor in a word in Your BCB Editor and then
press the F1 key eg.
ListBox1->Font->Style
then position the cursor in either ListBox1, Font or Style
press F1 and the right kind of help will show on the screen.
Or You can right Click in the editor and chose *Topic Search*
Kind regards
Asger
 

Re:Change the Font with code

Hi Asger,
Many thanks, yes I have got those help files, and doing as you say leads me
to your examples.
I shall have to wait till I arrive in another Maze and see how I get on.
Hind sight helps with this one..
Thanks
Penny
"Asger Joergensen" < XXXX@XXXXX.COM >wrote in message
Quote

Hi Penny

Penny hapeny says:
>Hi Gambit,
>
>Thanks for your replies.
>You say here read the documentation. With my purchase of Builder 6
>standard
>edition I only received a small book called Quick Start C++ Builder,
>this doesn't make any mention of Set's. The program Help when looking for
>set or Set doesn't produce anything related to this issue.

I only have BCB5 pro, but I would expect that Builder 6 standard
also have help files included if not I think they can be downloaded
from CodeGear.com.

In my BCB5 they are installed in:
CBuilder5\Help
and the helpfile in question is probably called:
bcb6vcl.hlp (mine is bcb5vcl.hlp)

If the help is installed it should be possible for You
to position the cursor in a word in Your BCB Editor and then
press the F1 key eg.

ListBox1->Font->Style

then position the cursor in either ListBox1, Font or Style
press F1 and the right kind of help will show on the screen.

Or You can right Click in the editor and chose *Topic Search*

Kind regards
Asger
 

Re:Change the Font with code

"Penny hapeny" < XXXX@XXXXX.COM >wrote in message
Quote
You say here read the documentation. With my purchase of Builder 6
standard edition I only received a small book called Quick Start C++
Builder, this doesn't make any mention of Set's.
I was referring to the VCL documentation that is installed along with the
IDE.
Quote
The program Help when looking for set or Set doesn't produce
anything related to this issue.
It does for me. Make sure you are looking at the right .hlp file to begin
with.
Quote
For an example, he then goes on to describe how to use it to add
attributes to the font style, and gives code examples similar to yours
and Asger's. But doesn't mention any other properties that use Sets.
There is no single list that mentions all of the Set-based properties. You
just have to read the documentation for each property you are interested in
using, and it will tell you what data type it uses, which will indicate
whether it is a Set or not. Just to name a few properties that are based on
Set:
TControl::Anchors
TControl::ControlState
TControl::ControlStyle
TForm::BorderIcons
Gambit