Autor Beitrag
gorrila
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mi 16.01.08 12:16 
Ich habe ungefähr 15 checkboxen und will nicht für jede eine if anweisung schreiben.
Wie kann ich nun die checkboxen mit i durchzählen ? (checkbox1....checkbox14)

Das war mein Versuch der leider nicht funktioniert
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.check;
var i:integer;
begin
  for i:=1 to 15 do
    begin
                       if checkbox[i].checked
                       then Teiler:=Teiler+1;
    end;
end;


Danke schonmal
oldmax
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 380


D3 Prof, D4 Prof
BeitragVerfasst: Mi 16.01.08 12:41 
Hi

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.check;  
var i:integer;  
begin  
  for i:=1 to 15 do  
    begin  
      if TCheckbox.FindComponent(Checkbox+IntToStr(i)).checked  
                       then Teiler:=Teiler+1;  
    end;  
end;

So zum Beispiel, wobei jetzt nicht auf "macht Sinn" geprüft...
Gruß oldmax

_________________
Zier dich nich so, ich krieg dich schon....
Zorro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 76

Win 2000, Win XP Pro
Delphi 7 Architect
BeitragVerfasst: Mi 16.01.08 12:51 
user profile iconoldmax hat folgendes geschrieben:
Hi

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.check;  
var i:integer;  
begin  
  for i:=1 to 15 do  
    begin  
      if TCheckbox.FindComponent(Checkbox+IntToStr(i)).checked  
                       then Teiler:=Teiler+1;  
    end;  
end;

So zum Beispiel, wobei jetzt nicht auf "macht Sinn" geprüft...
Gruß oldmax


Da es sich um ein Typecasting (und nicht um Property/Methode) handelt, muss es vermutlich
ausblenden Delphi-Quelltext
1:
if TCheckbox(FindComponent...					

statt
ausblenden Delphi-Quelltext
1:
if TCheckbox.FindComponent...					

heissen.

Greetz
Zorro
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 16.01.08 13:04 
Um den Source mal funktionierend und korrekt formatiert hier stehen zu haben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
  I: Integer;
begin
  for I := 1 to 15 do
    if TCheckBox(FindComponent('Checkbox' + IntToStr(I))).Checked then
      inc(Teiler);  // oder Teiler := Teiler + 1, falls nicht Integer
end;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
gorrila Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mi 16.01.08 15:05 
Titel: Klapp
Wunderbar es funktioniert !
Danke sehr an die Helfer