Board index » cppbuilder » How to set the color of all forms correctly (Screen->Forms[...]->Color)
Oren Halvani
CBuilder Developer |
How to set the color of all forms correctly (Screen->Forms[...]->Color)2004-07-20 11:09:11 PM cppbuilder104 hi dear builders, i want to change the color of all forms of my application at runtime when i'm click on the button ' cmdApply_FormsColorClick '..the button stores first the color-value into the registry and than it sets all the forms->color's via: for(int i = 0; i < Screen->FormCount; ++i) { Screen->Forms[i]->Color = StringToColor(reg->ReadString("Forms_Color")); } but something here doesn't work properly, i'm calling in the constructor of my mainform the function: " Read_FormsColor() " to read the color value from the registry (that the button stores) and stepping through all forms via Screen->Forms..to set the color to each form.. I get an AccessViolation error when i'm clicking the button ' cmdApply_FormsColorClick ' WHY ? WHAT is wrong...? can someone please help me..? Oren /***********************************************************/ // mainform constructor... __fastcall TForm1::TForm1(TComponent* Owner):TForm(Owner) { frmOptionen->Read_FormsColor(); // set all forms->color.. } void __fastcall TfrmOptionen::Read_FormsColor() { TRegistry* reg = new TRegistry; try { reg->OpenKey(RegistryKey, true); if(reg->ValueExists("Forms_Color")) { for(int i = 0; i < Screen->FormCount; ++i) { Screen->Forms[i]->Color = StringToColor(reg->ReadString("Forms_Color")); } } else { for(int i = 0; i < Screen->FormCount; ++i) { Screen->Forms[i]->Color = clSilver; // default color if registry-value is NOT existing.. } } reg->CloseKey(); } __finally {delete reg;} } // HERE something is causing the AccessViolation... void __fastcall TfrmOptionen::cmdApply_FormsColorClick(TObject *Sender) { TRegistry* reg = new TRegistry; try { reg->OpenKey(RegistryKey, true); reg->WriteString("Forms_Color", ColorToString(shpFormColor->Brush->Color)); reg->CloseKey(); delete reg; } __finally { delete reg; } // i guess HERE something seems not to be correct...but what..? for(int i = 0; i < Screen->FormCount; ++i) { Screen->Forms[i]->Color = shpFormColor->Brush->Color; } } // storing the color in a TShape (shpFormColor) void __fastcall TfrmOptionen::cmdSelectColorClick(TObject *Sender) { if(ColorDialog1->Execute()) { shpFormColor->Brush->Color = ColorDialog1->Color; } } |