Entwickler-Ecke

Delphi Language (Object-Pascal) / CLX - Automatischer Zugriff auf Klassenattribute


Xong - Fr 25.01.08 12:45
Titel: Automatischer Zugriff auf Klassenattribute
Hallo Forümmler!

Ich habe eine Beispielklasse:

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
TClass = class
  private
    [...]
  public
    Attribut1: Typ;
    Attribut2: Typ;
    Attribut3: Typ;
    Attribut4: Typ;
    Attribut5: Typ;
    Attribut6: Typ;

    constructor Create;
    [...]
end;

[...]

constructor TClass.Create;
begin
  { while Attribut <> nil do begin
      Initialisiere(Attribut);
      NextAttribut;
    end; }

end;

Nun kommt es immer wieder vor, dass ich neue Attribute einfügen muss.

Damit ich nicht immer alle/einige Methoden der Klasse umschreiben muss, wäre es praktisch, wenn es eine Funktion gäbe, mit der ich zumindest auf jedes Attribut in einer Schleife zugreifen könnte.
Ist so etwas möglich?

Danke für Hilfe,
Xong


Kroko - Fr 25.01.08 13:19


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
FAttr: array[0..??] of Typ

property Attr[const AIndex: Integer]: Typ read GetAttr write SetAttr;

function GetAttr(const AIndex: Integer): Typ;
begin
  Result := FAttr[AIndex];
end;

procedure SetAttr(const AIndex: Integer; Value: Typ);
begin
  FAttr[AIndex] := Value;
end;

zBsp so