The topic is interesting, but you need to dig deeper. In one of the projects, I implemented color palettes: color data was stored in a database, the user could create/customize the palette and select it. And on the code side, I made several procedures that updated all the colors according to the selected scheme.
I also repainted the images in the desired color, but this only works with images in the BMP format.
Below are the basic procedures.
procedure Colors_LoadTheme(AID: string);
// загрузка схемы
var
tmpSQL: string;
tmpDataSet: TDataSet;
tmpIndex: Integer;
tmpName: string;
begin
try
// извлекаем цвета, в приоритете - индекс, если данных по схеме ещё нет в базе, все цвета будут чёрными.
tmpSQL := 'SELECT ci.id, coalesce(cu.color,0) as color, coalesce(cu.id_color_item1,0) as colorIndex, ci.name ' +
' FROM color_item ci ' + ' LEFT JOIN color_ui cu on ci.id = cu.id_color_item ' +
'WHERE cu.id_color_theme = ' + AID;
SQLQuery(tmpSQL, tmpDataSet);
while not tmpDataSet.EOF do
begin
tmpName := tmpDataSet.FieldByName('name').asString;
tmpIndex := Colors_GetColorIndex(tmpName);
if tmpIndex = -1 then
ErrMsg('Colors_LoadTheme', 'Не найден цвет с именем ' + tmpName)
else
begin
UIColors[tmpIndex] := tmpDataSet.FieldByName('color').asInteger;
UICIndex[tmpIndex] := tmpDataSet.FieldByName('colorIndex').asInteger - 1;
end;
tmpDataSet.Next;
end;
finally
tmpDataSet.Free;
end;
// инициализировать цветные картинки
Colors_Image_Init;
end;
procedure Form_UpdateColor(AForm: TAForm);
// обновить цвета на форме
var
i: integer;
tmpPanel: TdbPanel;
tmpFormColor: TColor;
begin
// обновление цветов у элементов формы
tmpFormColor := Colors_Get(FORM_COLOR); // цвет формы
AForm.Color := Colors_Get(FORM_FRAME_COLOR); // цвет рамки
FindC(AForm, 'panWork', tmpPanel);
tmpPanel.Color := tmpFormColor;
FindC(AForm, 'panBottom', tmpPanel, False);
if tmpPanel <> nil then
tmpPanel.Color := tmpFormColor;
FindC(AForm, 'panTop', tmpPanel, False);
if tmpPanel <> nil then
tmpPanel.Color := tmpFormColor;
FindC(AForm, 'panTopFilter', tmpPanel, False);
if tmpPanel <> nil then
tmpPanel.Color := tmpFormColor;
FindC(AForm, 'panRight', tmpPanel, False);
if tmpPanel <> nil then
tmpPanel.Color := tmpFormColor;
// обновить цвета у компонент
for i := 0 to AForm.ComponentCount - 1 do
begin
VC_UpdateColor(AForm.Components[i]); // обновление цветов у компонент
end;
end;
procedure VC_UpdateColor(AComponent: TComponent;);
// обновление цвета
begin
try
case GetVClassName(AComponent.Name) of
T_FORM_CAPTION:
FormCaption_UpdateColor(TdbPanel(AComponent));
T_USER_DATA_PANEL:
UserDataPanel_UpdateColor(TdbPanel(AComponent));
T_ROUNDED_LABEL:
RoundedLabel_UpdateColor(TdbLabel(AComponent));
T_ROUNDED_PANEL:
RoundedPanel_UpdateColor(TdbPanel(AComponent));
T_ROUNDED_BUTTON:
RoundedButton_UpdateColor(TdbButton(AComponent));
T_ROUNDED_CHECKBOX:
RoundedCheckbox_UpdateColor(TdbCheckbox(AComponent));
T_ROUNDED_RADIOBOX:
RoundedRadiobox_UpdateColor(TdbCheckbox(AComponent));
T_ROUNDED_GRID:
RoundedGrid_UpdateColor(TdbStringGridEx(AComponent));
T_ROUNDED_COMBOBOX:
RoundedCombobox_UpdateColor(TdbComboBox(AComponent));
T_PARENT_COMBOBOX:
ParentCombobox_UpdateColor(TdbEdit(AComponent));
T_ROUNDED_MEMO:
RoundedMemo_UpdateColor(TdbMemo(AComponent));
T_ROUNDED_PAGECONTROL:
RoundedPagecontrol_UpdateColor(TdbPageControl(AComponent));
T_ROUNDED_DATEPICKER:
RoundedDatePicker_UpdateColor(TdbDateTimePicker(AComponent));
T_IMAGE_EDIT:
ImageEdit_UpdateColor(TdbImage(AComponent));
T_ROUNDED_EDIT:
RoundedEdit_UpdateColor(TdbEdit(AComponent));
T_FILESTORE:
FileStore_UpdateColor(TdbEdit(AComponent));
T_ROUNDED_TREE:
RoundedTree_UpdateColor(TdbStringGridEx(AComponent));
T_PHONE_EDIT:
PhoneEdit_UpdateColor(TdbEdit(AComponent));
T_EDIT_PAGECONTROL:
EditPagecontrol_UpdateColor(TdbPageControl(AComponent));
T_ROUNDED_SPLITTER:
RoundedSplitter_UpdateColor(TdbPanel(AComponent));
T_MAIN_MENU:
MainMenu_UpdateColor(TdbPanel(AComponent));
T_WIDGET:
Widget_UpdateColor(TdbPanel(AComponent));
T_SCROLL_BAR:
ScrollBar_UpdateColor(TdbPanel(AComponent));
T_ROUNDED_COLOR_EDIT:
RoundedColorEdit_UpdateColor(TdbEdit(AComponent));
T_CURRENCY_EDIT:
CurrencyEdit_UpdateColor(TdbEdit(AComponent));
T_NEWS_PANEL:
NewsPanel_UpdateColor(TdbPanel(AComponent));
T_DROP_DOWN_PANEL:
DropDownPanel_UpdateColor(TdbPanel(AComponent));
T_POP_UP_PANEL:
PopUpPanel_UpdateColor(TdbPanel(AComponent));
T_TOOLBAR:
ToolBar_UpdateColor(TdbPanel(AComponent));
T_ROUNDED_LIGHT_COMBO:
RoundedLightCombo_UpdateColor(TdbEdit(AComponent));
T_TASK_LEGEND_PANEL:
TaskLegendPanel_UpdateColor(TdbPanel(AComponent));
end;
except
ErrMsg('VC_UpdateColor(' + AComponent.Name + ')');
end;
end;
procedure RoundedLabel_UpdateColor(ALabel: TdbLabel);
// обновить цвет
var
S: TShape;
tmpForm: TAForm;
tmpName: string;
begin
CForm(ALabel, tmpForm);
tmpName := DeleteClassName(ALabel.Name);
//
ALabel.Color := Colors_Get(LABEL_COLOR);
ALabel.Font.Color := Colors_Get(LABEL_TEXT_COLOR);
if not ALabel.Transparent then
begin
S := TShape(tmpForm.FindComponent(T_SHAPE + tmpName + SX_RIGHT));
S.Pen.Color := ALabel.Color;
S.Brush.Color := ALabel.Color;
end;
end;
Unfortunately, I don’t have a simple example, but I hope the principle itself will be clear.
Визуальное программирование:
блог и
телеграм-канал.