Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  3 784

•  TDictionary Custom Sort  5 899

•  Fast Watermark Sources  5 694

•  3D Designer  8 469

•  Sik Screen Capture  6 031

•  Patch Maker  6 475

•  Айболит (remote control)  6 468

•  ListBox Drag & Drop  5 331

•  Доска для игры Реверси  94 924

•  Графические эффекты  6 674

•  Рисование по маске  5 789

•  Перетаскивание изображений  4 854

•  Canvas Drawing  5 230

•  Рисование Луны  4 953

•  Поворот изображения  4 497

•  Рисование стержней  3 186

•  Paint on Shape  2 430

•  Генератор кроссвордов  3 304

•  Головоломка Paletto  2 613

•  Теорема Монжа об окружностях  3 398

•  Пазл Numbrix  2 247

•  Заборы и коммивояжеры  2 907

•  Игра HIP  1 876

•  Игра Go (Го)  1 790

•  Симулятор лифта  2 124

•  Программа укладки плитки  1 856

•  Генератор лабиринта  2 295

•  Проверка числового ввода  1 983

•  HEX View  2 289

•  Физический маятник  1 955

 
скрыть

  Форум  

Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Как изменить цвет всех компонентов на форме в Run_time



Автор: Charles McNicoll

I would like to change the font color on all components on a form at runtime (and the components owned by the components etc). I devised a recursive algorithm using RTTI that accepts a TComponent as a parameter. It works to some extent, but I still have to use 'if' statements to cast the object to a particular descendant, resulting in about 30 lines of code to test for all of the components I use. Also, some objects (TColumnTitle), are not descended from TComponent, even though they have a font property.

This may do the trick (with D6 and maybe D5):

uses
  TypInfo;

{ ... }
var
  i: integer;
  aFont: TFont;
begin
  for i := 0 to aComponent.ComponentCount - 1 do
  begin
    aFont := TFont(GetOrdProp(aComponent.Components[i], 'Font'));
    if assigned(aFont) then
      aFont.Color := clWhite;
  end;
end;

With D4:

{ ... }
var
  i: integer;
  aFont: TFont;
  pi: PPropInfo;
begin
  for i := 0 to aComponent.ComponentCount - 1 do
  begin
    pi := GetPropInfo(aComponent.Components[i].ClassInfo, 'Font');
    if assigned(pi) then
      TFont(GetOrdProp(aComponent.Components[i], pi)).Color := clWhite;
  end;
end;




Похожие по теме исходники

Couleur (цветовая палитра)

Изменение цвета изображения

Run-Time




Copyright © 2004-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте