Autor Beitrag
Danny W.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 296

Windows XP, WIN 2000
Delphi 2005 PE
BeitragVerfasst: Di 14.11.06 11:55 
Hallo, Ich habe mal so ne frage (rein aus neugierde). Angenommen ich habe 50 checkboxfelder. Wie würde man es am besten realisieren, wenn man Abfragen möchte ob alle gleichzeitig "checked" sind...

ausblenden Delphi-Quelltext
1:
2:
if ((checkbox1.checked=true) and (checkbox2.checked=true) ... and (checkbox50.checked=true)) then
showmessage('Alle An!');


Diese Lösung wäre glaube ich doch ziemlich stumpfsinnig, oder? ;)

mfG

_________________
"Ich find den Fehler nicht. Der Artist wird immer als "Syntax Error" gezeigt :("
"Ach verdammt, der Artist heißt wirklich "Syntax Error" xD"
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Di 14.11.06 12:16 
ganz einfach =)

aus´m kopf raus...
ich geh davon aus das die alle 'Checkbox' heißen + wert 'n'
und in nem array of TCheckbox stehen =)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function allean: boolean;
var i: integer;
begin
 allean:= false;

 for i:= low(checkboxarray) to high(checkboxarray) do
 begin
  if TCheckbox(checkboxarray[i]).checked = false then
   exit;
 end;

 allean:= true;
end;


Sollten alle visuell schon aufm Formular sein so:
(auch wieder gleicher Namensteil + 'n');

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
function allean: boolean;
var i: integer;
    myCompo: TComponent;  
begin;
 //Funktionsrückgabe leer setzen
 allean:= false;

 for i:= 1 to 50 do
 begin
  myCombo:= findcomponent('Checkbox' + inttostr(i));
   if myCompo.classType = TCheckbox then
    if TCheckbox(myCompo).checked = false then
     exit;
 end;

 allean:= true;
end;


und prüfen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
if allean = true then
 showmessage('ALLE AN')
else
 showmessage('Nicht alle an');


LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
Danny W. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 296

Windows XP, WIN 2000
Delphi 2005 PE
BeitragVerfasst: Di 14.11.06 12:28 
Ok, vielen dank ^^

_________________
"Ich find den Fehler nicht. Der Artist wird immer als "Syntax Error" gezeigt :("
"Ach verdammt, der Artist heißt wirklich "Syntax Error" xD"
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 14.11.06 12:50 
Hallo,

oder man nimmt einen gemeinsamen Event-Handler für alle CheckBoxen.

ausblenden 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:
25:
26:
  procedure MyCheckBoxClick(Sender : TObject);  
//...
private
  iAllCBox : Integer;
//...
implementation

Procedure TForm1.FormCreate(Sender : TObject);
begin
  iAllCBox := 0;//initialisieren
end;  

procedure TForm1.MyCheckBoxClick(Sender : TObject);  
begin
  if TCheckBox(Sender).Checked then
    inc(iAllCBox)
    else
      dec(iAllCBox);
end; 

//abfragen
case iAllCBox of
  0     : showmessage('Keine CheckBox ist ...');
  1..49 : showmessage('Einige CheckBoxen sind ...');
  50    : showmessage('Alle CheckBoxen sind ...');
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Danny W. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 296

Windows XP, WIN 2000
Delphi 2005 PE
BeitragVerfasst: Di 14.11.06 12:57 
Auch sehr schöne Lösung. Sogar noch knapper :)
Kann ich ehrlich gesagt nur nicht wirklich anchvollziehen ^^

_________________
"Ich find den Fehler nicht. Der Artist wird immer als "Syntax Error" gezeigt :("
"Ach verdammt, der Artist heißt wirklich "Syntax Error" xD"
Jochen W.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 56



BeitragVerfasst: Di 14.11.06 13:06 
user profile iconMantis1987 hat folgendes geschrieben:
Diese Lösung wäre glaube ich doch ziemlich stumpfsinnig, oder? ;)

Ja, genauso wie die Idee, 50 Checkboxen auf einem Form zu platzieren. :mrgreen:
Danny W. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 296

Windows XP, WIN 2000
Delphi 2005 PE
BeitragVerfasst: Di 14.11.06 13:53 
Es geht ums prinzip :tongue:

_________________
"Ich find den Fehler nicht. Der Artist wird immer als "Syntax Error" gezeigt :("
"Ach verdammt, der Artist heißt wirklich "Syntax Error" xD"