![]() |
Suche Basisklasse, um Quellcode zu sparen
Hallo,
gibt es eine Art Basisklasse, damit ich nicht jedes Element extra ansprechen muss?
Delphi-Quellcode:
// TGroupBox
if Form.FindComponent(Node.Attributes['Name']) is TGroupBox then begin (Form.FindComponent(Node.Attributes['Name']) as TGroupBox).Caption:=Node.Attributes['Caption']; end; // TLabel if Form.FindComponent(Node.Attributes['Name']) is TLabel then begin (Form.FindComponent(Node.Attributes['Name']) as TLabel).Caption:=Node.Attributes['Caption']; end; // TBitBtn if Form.FindComponent(Node.Attributes['Name']) is TBitBtn then begin (Form.FindComponent(Node.Attributes['Name']) as TBitBtn).Caption:=Node.Attributes['Caption']; end; |
Re: Suche Basisklasse, um Quellcode zu sparen
Versuch es mal mit TControl.
|
Re: Suche Basisklasse, um Quellcode zu sparen
Hinweis: Das Array Components enthält alle Komponenten, die sich auf einem Form befinden.
Delphi-Quellcode:
for i := 0 to Self.ComponentCount-1 do begin
if (Components[i] is TLabel) then //machwas für Label if (Components[i] is TButton) then //machwas für Button // usw: end; |
Re: Suche Basisklasse, um Quellcode zu sparen
Zitat:
Aber man kann ja eine Hilfsklasse erstellen:
Delphi-Quellcode:
Dann könnte man es so lösen:
THackControl = class(TControl)
published property Caption; end;
Delphi-Quellcode:
Frank
Var
AComponent: TComponent; begin AComponent := Form.FindComponent(Node.Attributes['Name']); if Assigned(AComponent) then THackControl(AComponent).Caption := Node.Attributes['Caption']; ... |
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:01 Uhr. |
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