by Team » Sun, 29 Feb 2004 11:22:32
"Oren Halvani" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
You are going about it the wrong way. See further below for an explanation.
You don't, because that is not the correct way to approach the issue in the
first place.
The Font->Size is not a TRichEdit to begin with. You cannot cast it to one,
or vice versa.
You would be better off just moving your Registry code into a separate
function of its own that takes a TFont* as a parameter. For example:
const AnsiString MyFontsKey = "\\Software\\MyKey\\Fonts\\";
bool __fastcall SaveFontToRegistry(const AnsiString &Name, TFont *Font)
{
TRegistry* reg = NULL;
bool Success = false;
try
{
reg = new TRegistry;
try
{
reg->RootKey = whatever;
if( reg->OpenKey(MyFontsKey + "\\" + Name, true) )
{
reg->WriteString("Font_Name", Font->Name);
reg->WriteInteger("Font_Size", Font->Size);
//...
reg->CloseKey();
Success = true;
}
}
__finally {
delete reg;
}
}
catch(const Exception &) {}
return Success;
}
bool __fastcall ReadFontFromRegistry(const AnsiString &Name, TFont
*Font)
{
TRegistry* reg = NULL;
bool Success = false;
try
{
reg = new TRegistry;
try
{
reg->RootKey = whatever;
if( reg->OpenKeyReadOnly(MyFontsKey + "\\" + Name) )
{
Font->Name = reg->ReadString("Font_Name");
Font->Size = reg->ReadInteger("Font_Size");
//...
reg->CloseKey();
Success = true;
}
}
__finally {
delete reg;
}
}
catch(const Exception &) {}
return Success;
}
Then you can read/write your RichEdits as needed, ie:
for(int x = 0; x < Screen->Forms->Count; ++x)
{
TForm *pForm = Screen->Forms[x];
for(int y = 0; y < pForm->ComponentCount; ++y)
{
TRichEdit *pRichEdit =
dynamic_cast<TRichEdit*>(pForm->Components[x]);
if( pRichEdit )
{
if( !SaveFontToRegistry(pForm->Name + "|" + pRichEdit->Name,
pRichEdit->Font) )
// error saving the Font...
}
}
}
//...
for(int x = 0; x < Screen->Forms->Count; ++x)
{
TForm *pForm = Screen->Forms[x];
for(int y = 0; y < pForm->ComponentCount; ++y)
{
TRichEdit *pRichEdit =
dynamic_cast<TRichEdit*>(pForm->Components[x]);
if( pRichEdit )
{
if( !ReadFontFromRegistry(pForm->Name + "|" +
pRichEdit->Name, pRichEdit->Font) )
// error reading the Font...
}
}
}
Gambit