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

•  Animation Loaders  649

•  DeLiKaTeS Tetris (Тетрис)  5 660

•  TDictionary Custom Sort  7 622

•  Fast Watermark Sources  7 311

•  3D Designer  10 512

•  Sik Screen Capture  7 831

•  Patch Maker  8 058

•  Айболит (remote control)  8 115

•  ListBox Drag & Drop  6 922

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

•  Графические эффекты  8 181

•  Рисование по маске  7 579

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

•  Canvas Drawing  6 547

•  Рисование Луны  6 476

•  Поворот изображения  5 656

•  Рисование стержней  4 577

•  Paint on Shape  3 282

•  Генератор кроссвордов  4 268

•  Головоломка Paletto  3 404

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

•  Пазл Numbrix  2 745

•  Заборы и коммивояжеры  3 646

•  Игра HIP  2 451

•  Игра Go (Го)  2 435

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

•  Программа укладки плитки  2 284

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

•  Проверка числового ввода  2 506

•  HEX View  2 906

 
скрыть

  Форум  

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-2026 "Delphi Sources" by «SiteAnalyzer». Delphi World FAQ

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