Einzelnen Beitrag anzeigen

Delphi.Narium

Registriert seit: 27. Nov 2017
2.415 Beiträge
 
Delphi 7 Professional
 
#2

AW: Konstantenausdruck erwartet

  Alt 26. Jan 2019, 13:05
Case geht nicht mit Variabeln, links vom Doppelpunkt muss eine Konstante stehen.
Delphi-Quellcode:
if i = 0 then ...
else if i = FRadioButtonList.Count -1 then ...
else der Rest
ist genauso flexibel wie Dein Case. Zwei Werte (1. und letztes Element) werden explizit abgefragt, der Rest geht in die Else am Ende.
Delphi-Quellcode:
procedure TRadioButtonsFrame.RadioButtonPosition;
  var i, x, y: Integer;
begin
  x := FRadioButtonList.Count - 1;
  For i := 0 to x do
  begin
    FRadioButtonList.Items[i].Left := 12;
    FRadioButtonList.Items[i].Top := 12;
    FRadioButtonList.Items[i].AlignWithMargins := true;
    FRadioButtonList.Items[i].Margins.Top := 5;
    FRadioButtonList.Items[i].Margins.Bottom := 5;
    FRadioButtonList.Items[i].Margins.Left := 80;
    FRadioButtonList.Items[i].Margins.Right := 25;
    if (i > 0) and (i < x) then FRadioButtonList.Items[i].Align := alTop;
  end;
end;
Wenn man dann noch in allen Fällen identische Codeteile nicht mehrfach aufführt, wird das schon deutlich kürzer.
  Mit Zitat antworten Zitat