Autor Beitrag
Calyptus
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 386

Win Xp Prof
D3, D6 Pers, D7 Ent
BeitragVerfasst: Fr 28.10.05 20:04 
Also, ich hab ein Problem von dem ich nichts so genau weiß wie ich's beschrieben soll, deshalb war ich auch beim Suchen erfolglos.

Es geht um folgendes:

Ich möchte Attribute für verschiedene Komponenten auf meiner Form1 dynamisch ändern (also nicht einmal Einstellen und fertig). Die Informationen dazu werden aus einer XML Datei ausgelesen, wo unter anderem der Name der Komponente und auch der 'Typ' also TLabel, TButton usw. drinsteht.
Bis jetzt mache ich das ganze so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
component := 'Label1'; // nur mal als Beispiel

case typ of

1: with Form1.FindComponent(component) as TLabel do
    begin
     Color := clRed; // auch nur ein Beispiel
    end;

2: with Form1.FindComponent(component) as TButton do
    begin
     Color := clRed;
    end;

3: with Form1.FindComponent(component) as TMemo do
     begin
      Color := clRed;
     end;
        
end;


und ich hätte aber gerne sowas in der Richtung wie

ausblenden Delphi-Quelltext
1:
2:
with Form1.FindComponent(component) as CompArray[typ] do
 Color := clRed;


Ich bräuchte also ein Array der die Werte TLabel, TForm, TMemo usw. annehmen kann, und genau an der Stelle komme ich nicht weiter.

Ich hoffe mal ihr versteht was ich meine ;)

_________________
Luft- und Raumfahrtechnik an der Uni Stuttgart
Bernhard Geyer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 721
Erhaltene Danke: 3



BeitragVerfasst: Sa 29.10.05 13:10 
ausblenden Delphi-Quelltext
1:
CompArray: array[0..2] of TControlClass = (TLabel, TButton, TMemo);					
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 29.10.05 13:17 
Das geht so nicht ...
Du kannst aber über SetOrdPropValue (Unit TypInfo) anhand der Laufzeit-Typ-Informationen soetwas realisieren. Ein Beispiel dazu gibt es in der Delphi-Library.

//Edit: Siehe z.B. hier: www.delphi-forum.de/viewtopic.php?t=28204

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.