Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Alle Komponenten einer Application ändern (https://www.delphipraxis.net/74095-alle-komponenten-einer-application-aendern.html)

Michael Habbe 27. Jul 2006 23:33

Re: Alle Komponenten einer Application ändern
 
Sicherheitshalber auch noch nach Label schauen:
Delphi-Quellcode:
for I := 0 to Application.ComponentCount-1 do
begin
  if Application.Components(I) is TForm then
  begin
    for i2 := 0 to TForm(Application.Components(I)).ComponentCount -1 do
      if TForm(Application.Components(I)).Components[i2] is TLabel then // <-- hier
        TLabel(TForm(Application.Components(I)).Components[i2]).Font.Color := clRed;
  end;
end;

Dragon27 27. Jul 2006 23:41

Re: Alle Komponenten einer Application ändern
 
Hallo,

danke der Code funct jetzt bei Formularen. Nun benutze ich auch Frames und habe das hier geändert aber es geht nicht :-( wieso?


Delphi-Quellcode:
    if Application.Components[I] is TFrame then
  begin
    for i2 := 0 to TFrame(Application.Components[I]).ComponentCount -1 do
      if TFrame(Application.Components[I]).Components[i2] is TLabel then // <-- hier
        TLabel(TFrame(Application.Components[I]).Components[i2]).Font.Color := clRed;
  end;

marabu 28. Jul 2006 06:53

Re: Alle Komponenten einer Application ändern
 
Guten Morgen.

Zuerst kapselt man die benötigte Funktionalität:

Delphi-Quellcode:
// uses TypInfo;

procedure SetProperty(c: TComponent; cClass, cName: String; cValue: Variant);
var
  i: Integer;
  ppi: PPropInfo;
begin
  if SameText(c.ClassName, cClass) then
  begin
    ppi := GetPropInfo(c, cName);
    if Assigned(ppi) then
      SetPropValue(c, cName, cValue);
  end;
  for i := 0 to Pred(c.ComponentCount) do
    SetProperty(c.Components[i], cClass, cName, cValue);
end;
Dann wählt man einen geeigneten Zeitpunkt um sie abzurufen:

Delphi-Quellcode:
SetProperty(Application, 'TLabel', 'Color', clRed);
Grüße vom marabu


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:17 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz