Discussion:
Change the Font with code
(too old to reply)
Remy Lebeau (TeamB)
2008-02-07 17:52:34 UTC
Permalink
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
Penny hapeny
2008-02-08 12:44:33 UTC
Permalink
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
Post by Remy Lebeau (TeamB)
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
// 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
EditControls[Row][Col]->Font->Style = TFontStyles() << fsItalic;
Gambit
Asger Joergensen
2008-02-08 13:02:29 UTC
Permalink
Hi Penny
Post by Penny hapeny
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
Penny hapeny
2008-02-08 15:35:40 UTC
Permalink
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

.
Post by Asger Joergensen
Hi Penny
Post by Penny hapeny
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
Remy Lebeau (TeamB)
2008-02-08 17:50:31 UTC
Permalink
Post by Penny hapeny
How do you know what Properties are set
Read the documentation.


Gambit
Penny hapeny
2008-02-10 15:36:01 UTC
Permalink
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
Post by Remy Lebeau (TeamB)
Post by Penny hapeny
How do you know what Properties are set
Read the documentation.
Gambit
Asger Joergensen
2008-02-10 16:00:29 UTC
Permalink
Hi Penny
Post by Penny hapeny
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
Penny hapeny
2008-02-10 17:40:19 UTC
Permalink
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
Post by Asger Joergensen
Hi Penny
Post by Penny hapeny
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.
CBuilder5\Help
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
Remy Lebeau (TeamB)
2008-02-11 18:55:31 UTC
Permalink
Post by Penny hapeny
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.
Post by Penny hapeny
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.
Post by Penny hapeny
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

Remy Lebeau (TeamB)
2008-02-08 17:50:05 UTC
Permalink
Post by Penny hapeny
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
Continue reading on narkive:
Loading...