Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#5

AW: bessere lösung für prozeduren

  Alt 29. Okt 2011, 09:26
Hübscher, besser wartbar fände ich etwas in der Art:
Delphi-Quellcode:
implementation

{$R *.dfm}

type
TInfoRec=Record
  Nr:Integer;
  Caption:String;
End;

const
InfoRecArray:Array[1..5,1..4] of TInfoRec=(
                                         (
                                          (Nr : 1;Caption :'Name')
                                          , (Nr : 2;Caption :'Kunden Nr')
                                          , (Nr : -1;Caption :'')
                                          , (Nr : -1;Caption :'')
                                          ),
                                          (
                                          (Nr : 1;Caption :'Name')
                                          , (Nr : 3;Caption :'Artikel Nr')
                                          , (Nr : 6;Caption :'Bezeichnung')
                                          , (Nr : 7;Caption :'Lieferant')
                                          ),
                                          (
                                          (Nr : 2;Caption :'Kunden Nr')
                                          , (Nr : 5;Caption :'Rechnungs Nr')
                                          , (Nr : -1;Caption :'')
                                          , (Nr : -1;Caption :'')
                                          ),
                                          (
                                          (Nr : 1;Caption :'Name')
                                          , (Nr : 2;Caption :'Kunden Nr')
                                          , (Nr : 4;Caption :'Auftrags Nr')
                                          , (Nr : -1;Caption :'')
                                          ),
                                          (
                                          (Nr : 1;Caption :'Name')
                                          , (Nr : -1;Caption :'')
                                          , (Nr : -1;Caption :'')
                                          , (Nr : -1;Caption :'')
                                          ));

procedure TForm1.DisplayArray(Nr:Integer);
var
  i:Integer;
  l:TLabel;
begin
  Combobox1.Items.Clear;
  for I := 1 to 4 do
      begin
         l := TLabel(FindComponent('Label' + IntToStr(i)));
         if Assigned(l) then
            begin
              l.Visible := InfoRecArray[Nr,i].Nr >0;
              l.Caption := IntToStr(InfoRecArray[Nr,i].Nr) + ' = ' + InfoRecArray[Nr,i].Caption;
              if l.Visible then Combobox1.Items.Add(IntToStr(InfoRecArray[Nr,i].Nr));
            end;
      end;
   Combobox1.ItemIndex := 0;
end;

procedure TForm1.Button1Click(Sender: TObject);

begin
 DisplayArray(1);
end;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat