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

•  DeLiKaTeS Tetris (Тетрис)  4 447

•  TDictionary Custom Sort  6 479

•  Fast Watermark Sources  6 272

•  3D Designer  9 220

•  Sik Screen Capture  6 609

•  Patch Maker  6 992

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

•  ListBox Drag & Drop  5 864

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

•  Графические эффекты  7 193

•  Рисование по маске  6 489

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

•  Canvas Drawing  5 739

•  Рисование Луны  5 449

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

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

•  Paint on Shape  2 803

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

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

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

•  Пазл Numbrix  2 481

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

•  Игра HIP  2 132

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

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

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

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

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

•  HEX View  2 590

•  Физический маятник  2 202

 
скрыть

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;