 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Steven Guest
|
Posted: Sat May 06, 2006 11:14 pm Post subject: Various font settings |
|
|
I am using the following to store and retrieve some font settings,
struct TConfigSetting
{
AnsiString pFont;
TColor pColor;
int pFontSize;
int pBold;
};
I am storing the values to an .ini file.
[font settings]
fontname=FontDialog1->Font->Name;
fontsize=FontDialog1->Font->Size;
fontcolor=ColorDialog1->Color;
Then I retrieve the values from the .ini file and use them like this.
Label1->Font->Color = TColor(value from the ini file);
Label1->Font->Name = (string value from the ini file)
label1->Font->Size = (int value from the ini file)
Now, doing the above seems to work okay when storing and retrieving
the information. The values are actually used when I apply them. But
there
are two more values I would like to use, but I don't know how to store
them
and retrieve them. Those are the *styles* and *effects*, how do I go
about
in storing and retrieving these values in my .ini file?
Appreciate it. |
|
| Back to top |
|
 |
Elmar Baumann Guest
|
Posted: Sun May 07, 2006 8:14 am Post subject: Re. Various font settings |
|
|
| Quote: | Steven wrote in Article <445d2a46$1 (AT) newsgroups (DOT) borland.com
with Subject: Various font settings, on 07.05.2006 00:59:24
Now, doing the above seems to work okay when storing and retrieving
the information. The values are actually used when I apply them. But here
are two more values I would like to use, but I don't know how to store them
and retrieve them. Those are the *styles* and *effects*, how do I go >about
in storing and retrieving these values in my .ini file?
Appreciate it.
|
Hello,
you have to convert the TFontStyles to Strings - save them in a INI-File
and convert them back if you load the INI-File, i have an example to save&set
the Color&Font of a TList using TStrings, the inifile in this case is a simple
TStringList [using LoadFromFile/SaveToFile]:
SAVE Section
------------
TStrings *output;
output = new TStringList();
// Settings of UserList
inifile->Add(ColorToString(UserList->Color));
inifile->Add(UserList->Font->Name);
inifile->Add(UserList->Font->Color);
inifile->Add(AnsiString(UserList->Font->Size));
//
if(UserList->Font->Style.Contains(fsBold))
{
output->BeginUpdate();
output->Add("fsBold");
output->EndUpdate();
}
else
{
output->BeginUpdate();
output->Add("0");
output->EndUpdate();
}
if(UserList->Font->Style.Contains(fsItalic))
{
output->BeginUpdate();
output->Add("fsItalic");
output->EndUpdate();
}
else
{
output->BeginUpdate();
output->Add("0");
output->EndUpdate();
}
if(UserList->Font->Style.Contains(fsUnderline))
{
output->BeginUpdate();
output->Add("fsUnderline");
output->EndUpdate();
}
else
{
output->BeginUpdate();
output->Add("0");
output->EndUpdate();
}
if(UserList->Font->Style.Contains(fsStrikeOut))
{
output->BeginUpdate();
output->Add("fsStrikeOut");
output->EndUpdate();
}
else
{
output->BeginUpdate();
output->Add("0");
output->EndUpdate();
}
inifile->Add(output->operator [](0));
inifile->Add(output->operator [](1));
inifile->Add(output->operator [](2));
inifile->Add(output->operator [](3));
delete output;
LOAD Section
------------
UserList->Color = StringToColor(inifile->operator [](63)); // UserList Datai was stored at position 63
UserList->Font->Name = inifile->operator [](64) ;
UserList->Font->Color = StringToColor(inifile->operator [](65));
UserList->Font->Size = inifile->operator [](66).ToInt();
if(inifile->operator [](67) == "fsBold")
{
UserList->Font->Style = TFontStyles() << fsBold;
}
if(inifile->operator [](6 == "fsItalic")
{
UserList->Font->Style = TFontStyles() << fsItalic;
}
if(inifile->operator [](69) == "fsUnderline")
{
UserList->Font->Style = TFontStyles() << fsUnderline;
}
if(inifile->operator [](70) == "fsStrikeOut")
{
UserList->Font->Style = TFontStyles() << fsStrikeOut;
}
Regards
Elmar Baumann
------------------------------------------------------------------------------
Indy9 NNTP Internet News Reader/Writer, E. Baumann Software 2005
Portions of this Software are Copyright (c) 1993 - 2005,
Chad Z. Hower (Kudzu) and the Indy Pit Crew
<http://www.IndyProject.org/> |
|
| Back to top |
|
 |
Michel Leunen Guest
|
Posted: Sun May 07, 2006 10:14 am Post subject: Re: Re. Various font settings |
|
|
Elmar Baumann wrote:
| Quote: | the inifile in this case is a simple
TStringList [using LoadFromFile/SaveToFile]:
TStrings *output;
output = new TStringList();
// Settings of UserList
inifile->Add(ColorToString(UserList->Color));
inifile->Add(UserList->Font->Name);
inifile->Add(UserList->Font->Color);
inifile->Add(AnsiString(UserList->Font->Size));
|
I suppose you meant:
output->Add(...);
....
| Quote: | if(UserList->Font->Style.Contains(fsBold))
{
output->BeginUpdate();
output->Add("fsBold");
output->EndUpdate();
}
else
{
output->BeginUpdate();
output->Add("0");
output->EndUpdate();
}
|
If you really need to encapsulate your code with
BeginUdate()/EndUpdate(), write your code like this instead:
output->BeginUpdate();
if(UserList->Font->Style.Contains(fsItalic))
{
...
}
else
{
...
}
if(...)
{
...
}
....
....
output->EndUpdate()
| Quote: | inifile->Add(output->operator [](0));
inifile->Add(output->operator [](1));
inifile->Add(output->operator [](2));
inifile->Add(output->operator [](3));
|
Strange way to access the strings.
TStringList has a property to retrieve the strings and it's called Strings:
inifile->Add(output->Strings[0]);
....
But what type is inifile? TIniFile doesn't have an Add() method.
Your code is quite confusing.
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
http://www.leunen.com/
---------------------------------------- |
|
| Back to top |
|
 |
Elmar Baumann Guest
|
Posted: Sun May 07, 2006 11:14 am Post subject: Re. Re: Re. Various font settings |
|
|
| Quote: | Michel Leunen wrote in Article <445dbdf9$1 (AT) newsgroups (DOT) borland.com
with Subject: Re: Re. Various font settings, on 07.05.2006 11:32:10
Elmar Baumann wrote:
the inifile in this case is a simple
TStringList [using LoadFromFile/SaveToFile]:
But what type is inifile? TIniFile doesn't have an Add() method.
Your code is quite confusing.
|
Hello,
inifile is a global defined TStringList - as i said in the first line.
this demo don't use TIniFile.
Regards
Elmar Baumann
------------------------------------------------------------------------------
Indy9 NNTP Internet News Reader/Writer, E. Baumann Software 2005
Portions of this Software are Copyright (c) 1993 - 2005,
Chad Z. Hower (Kudzu) and the Indy Pit Crew
<http://www.IndyProject.org/> |
|
| Back to top |
|
 |
Steven Guest
|
Posted: Sun May 07, 2006 3:14 pm Post subject: Re: Re. Various font settings |
|
|
Elmar,
Thanks a lot, let me put this into action now.
Steven |
|
| Back to top |
|
 |
Elmar Baumann Guest
|
Posted: Sun May 07, 2006 3:14 pm Post subject: Re. Re: Re. Various font settings |
|
|
| Quote: | Michel Leunen wrote in Article <445dbdf9$1 (AT) newsgroups (DOT) borland.com
with Subject: Re: Re. Various font settings, on 07.05.2006 11:32:10
But what type is inifile? TIniFile doesn't have an Add() method.
Your code is quite confusing.
|
a correction in your advice:
SAVE Section
------------
inifile->BeginUpdate();
. . .
// Settings of UserList
inifile->Add(ColorToString(UserList->Color));
inifile->Add(UserList->Font->Name);
inifile->Add(UserList->Font->Color);
inifile->Add(AnsiString(UserList->Font->Size));
//
if(UserList->Font->Style.Contains(fsBold))
{
inifile->Add("fsBold");
}
else
{
inifile->Add("0");
}
if(UserList->Font->Style.Contains(fsItalic))
{
inifile->Add("fsItalic");
}
else
{
inifile->Add("0");
}
if(UserList->Font->Style.Contains(fsUnderline))
{
inifile->Add("fsUnderline");
}
else
{
inifile->Add("0");
}
if(UserList->Font->Style.Contains(fsStrikeOut))
{
inifile->Add("fsStrikeOut");
}
else
{
inifile->Add("0");
}
inifile->EndUpdate();
. . .
LOAD Section
------------
UserList->Color = StringToColor(inifile->operator [](63)); // UserList Data was stored at position 63
UserList->Font->Name = inifile->operator [](64) ;
UserList->Font->Color = StringToColor(inifile->operator [](65));
UserList->Font->Size = inifile->operator [](66).ToInt();
if(inifile->operator [](67) == "fsBold")
{
UserList->Font->Style = TFontStyles() << fsBold;
}
if(inifile->operator [](6 == "fsItalic")
{
UserList->Font->Style = TFontStyles() << fsItalic;
}
if(inifile->operator [](69) == "fsUnderline")
{
UserList->Font->Style = TFontStyles() << fsUnderline;
}
if(inifile->operator [](70) == "fsStrikeOut")
{
UserList->Font->Style = TFontStyles() << fsStrikeOut;
}
Regards
Elmar Baumann
------------------------------------------------------------------------------
Indy9 NNTP Internet News Reader/Writer, E. Baumann Software 2005
Portions of this Software are Copyright (c) 1993 - 2005,
Chad Z. Hower (Kudzu) and the Indy Pit Crew
<http://www.IndyProject.org/> |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|