Autor Beitrag
HaseKlopfer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Sa 20.07.02 00:48 
Hallo!

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
var ArrayBoolean[1..5] of Boolean;

ArrayBoolean[1] := Checkbox1.Checked;
ArrayBoolean[2] := Checkbox2.Checked;
ArrayBoolean[3] := Checkbox3.Checked;
ArrayBoolean[4] := Checkbox4.Checked;
ArrayBoolean[5] := Checkbox5.Checked;


Nehmen wir an, ich möchte in diesem Array nicht den Status von 5 Checkboxes speichern sondern von 500 - gibts eine schöne, kurze Alternative zu den obigen Zeilen? = eine Art FOR Schleife?

Danke!!
Liebe Grüße
Johannes
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Sa 20.07.02 02:01 
Hi,

das sollte so gehen:

ausblenden Quelltext
1:
2:
FOR i := 5 DOWNTO 1 DO 
  ArrayBoolean[i] := tCheckBox(FindComponent('Checkbox' + IntToStr(i))).Checked;


Gruß
Klabautermann
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 20.07.02 08:57 
500 Checkboxen?
Alle im selben Formular? :shock:

Da wäre es wohl mal Zeit, über eine geänderte Benutzerführung nachzudenken. Würde eine CheckListBox weiterhelfen? A) sie spart Platz, und B) kann man auch in einer for-Schleife den Status jedes einzelnen Items auslesen.
HaseKlopfer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: So 21.07.02 00:34 
aber nein :) hab die zahl 500 als beispiel gewählt... damit es drastisch klingt und ich wirklich eine verkürzung brauch... ich hab nur 6 checkboxen, am formular ;)


@Klabautermann - Bekomme leider einen EAccessViolation Fehler.. :(

lg,
johannes
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: So 21.07.02 15:10 
Hallo,

HaseKlopfer hat folgendes geschrieben:
@Klabautermann - Bekomme leider einen EAccessViolation Fehler.. :(

ich habe das Beispiel zu testzwecken grade mal folgendermaßen abgewandelt:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button1Click(Sender: TObject);
VAR
    i : Integer;
begin
  FOR i := 5 DOWNTO 1 DO
   tCheckBox(FindComponent('Checkbox' + IntToStr(i))).Checked := NOT tCheckBox(FindComponent('Checkbox' + IntToStr(i))).Checked;
end;


Es funtioniert wunderbar. Du musst natürlich sicherstellen, das die Checkboxen auch wirklich Checkbox1 bis Checkbox5 heißen und zu dem selben Formular gehören wie diese Funktion.

Gruß
Klabautermann