Board index » cppbuilder » TRichEdit & TFontDialog

TRichEdit & TFontDialog


2005-06-08 01:19:36 AM
cppbuilder20
Hi,
I noticed something that I *think* it's weird with the
TRichEdit &.TFontDialog (the whole code is below ).
On Form1 place RichEdit1, FontDialog1 and Button1.
I wanted to save the last used (basic) font characteristics
to INI and later to reload it at startup. Everytrhing worked
fine untl I noticed that even if I press Cancel at FontDialog1
the last saved & applied font (which was loaded at startup)
is missed.
Steps to reproduce the problem:
1) Open fontdialog and select some new font,
ie. size=24, color=Red
2) Press OK to FontDialog
3) Close the app
4) Reopen the app
5) The lastest font, size and color ar loaded from INI and applied...
6) Open font dialog again and the press Cancel
THE FONT CHARACTERISTICS ARE GONE!
What I'm missing?
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TIniFile *pIni = NULL;
try
{
try
{
pIni = new TIniFile( ExtractFilePath( ParamStr(0) ) +
"konfiguracija.ini" );
RichEdit1->Font->Name = pIni->ReadString( "RichEdit", "Name",
"Arial" );
RichEdit1->Font->Color = StringToColor( pIni->ReadString(
"RichEdit", "Color", "clBlack" ) );
RichEdit1->Font->Height = pIni->ReadInteger( "RichEdit",
"Height", -11 );
}
catch ( const Exception &e )
{
// ...
}
}
__finally
{
if ( pIni )
delete pIni;
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if ( FontDialog1->Execute() );
{
RichEdit1->Font = FontDialog1->Font;
}
}
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
TIniFile *pIni = NULL;
try
{
try
{
pIni = new TIniFile( ExtractFilePath( ParamStr(0) ) +
"konfiguracija.ini" );
pIni->WriteString( "RichEdit", "Name", RichEdit1->Font->Name );
pIni->WriteString( "RichEdit", "Color", ColorToString(
RichEdit1->Font->Color ) );
pIni->WriteInteger( "RichEdit", "Height",
RichEdit1->Font->Height );
}
catch ( const Exception &e )
{
// ...
}
}
__finally
{
if ( pIni )
delete pIni;
}
}
--
Best regards,
Vladimir Stefanovic
 
 

Re:TRichEdit & TFontDialog

I placed this:
FontDialog1->Font = RichEdit1->Font;
in front of opening, and that solved the problem but I'm still curious...
--
Best regards,
Vladimir Stefanovic
"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
Quote
Hi,

I noticed something that I *think* it's weird with the
TRichEdit &.TFontDialog (the whole code is below ).

On Form1 place RichEdit1, FontDialog1 and Button1.

I wanted to save the last used (basic) font characteristics
to INI and later to reload it at startup. Everytrhing worked
fine untl I noticed that even if I press Cancel at FontDialog1
the last saved & applied font (which was loaded at startup)
is missed.

Steps to reproduce the problem:

1) Open fontdialog and select some new font,
ie. size=24, color=Red
2) Press OK to FontDialog
3) Close the app
4) Reopen the app
5) The lastest font, size and color ar loaded from INI and applied...
6) Open font dialog again and the press Cancel

THE FONT CHARACTERISTICS ARE GONE!

What I'm missing?


__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TIniFile *pIni = NULL;
try
{
try
{
pIni = new TIniFile( ExtractFilePath( ParamStr(0) ) +
"konfiguracija.ini" );

RichEdit1->Font->Name = pIni->ReadString( "RichEdit", "Name",
"Arial" );
RichEdit1->Font->Color = StringToColor( pIni->ReadString(
"RichEdit", "Color", "clBlack" ) );
RichEdit1->Font->Height = pIni->ReadInteger( "RichEdit",
"Height", -11 );
}
catch ( const Exception &e )
{
// ...
}
}
__finally
{
if ( pIni )
delete pIni;
}
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
if ( FontDialog1->Execute() );
{
RichEdit1->Font = FontDialog1->Font;
}
}

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
TIniFile *pIni = NULL;
try
{
try
{
pIni = new TIniFile( ExtractFilePath( ParamStr(0) ) +
"konfiguracija.ini" );

pIni->WriteString( "RichEdit", "Name", RichEdit1->Font->Name );
pIni->WriteString( "RichEdit", "Color", ColorToString(
RichEdit1->Font->Color ) );
pIni->WriteInteger( "RichEdit", "Height",
RichEdit1->Font->Height );
}
catch ( const Exception &e )
{
// ...
}
}
__finally
{
if ( pIni )
delete pIni;
}
}



--
Best regards,
Vladimir Stefanovic

 

Re:TRichEdit & TFontDialog

"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
LOL!
First off I thought that you didn't do smth right with the ini fie...
but no, it's smth wose... :) , you've put a semicolon that makes your if
statement do nothing at all, take a look :)
if ( FontDialog1->Execute() ); <------------- I didn't put a lot of my
attention too at the beginning,,, but when I...
{
RichEdit1->Font = FontDialog1->Font;
}
// <------------- tried to put else statement here, it failed, sure, because
it was misplaced one, LOL, sorry for laughter :)
Cheers
 

{smallsort}

Re:TRichEdit & TFontDialog

Quote
if ( FontDialog1->Execute() ); <------------- I didn't put a lot of my
Thanks... I almost go mad :)
--
Best regards,
Vladimir Stefanovic