Autor Beitrag
hansg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: So 19.01.03 15:37 
Hallo,
kann man mehrere Checkboxen mit einer Schleife auf einmal den Haken
setzen bzw. wegnehmen oder muß ich alle mit checkbox1.checked:=true; bzw. mit checkbox1.checked:=false; alle zu Fuß setzten?


Gruß Hans
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 19.01.03 15:48 
Hallo,

lese mal dieses Topic, ich denke das wird einige deiner Fragen beantworten.

Gruß
Klabautermann
hansg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: So 19.01.03 16:18 
Hallo,
irgendwie klappt das nicht:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
var checkbox: array[1..20] of TCheckbox;
    i: integer;
begin
   for i:=1 to 20 do
   begin
     checkbox[i].checked:=true;
   end;
end;


wo liegt der Fehler, Delphi stürzt dann ab?



Gruß Hans
Wolff68
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 302
Erhaltene Danke: 1

WinXP home
D6 Prof
BeitragVerfasst: So 19.01.03 17:03 
TCeckbox ist ein Objekt ! (Und noch dazu ein visuelles)
Mit var checkbox : Array [1..20] of TCheckbox weist Du nur der Variablen eine TCheckbox zu. Du musst sie aber noch erzeugen!

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
For i := 1 to 20 do begin
  CheckBox[i] := TCheckBox.Create(self);
  With CheckBox[i] do begin
    Parent := Form1; // bzw das Object, auf dem die Checkbox erscheinen soll
    Top := i*24;
    Left := 8;
    { eventuell noch weitere Eingenschaften einstellen... }
  end;
end;


(Steht übrigends auch so im 2. Beitrag des Topics, das Dir Klabautermann empfohlen hat)

_________________
"Der Mensch ist nicht was er sich vorstellt oder wünscht zu sein, sondern das was andere in ihm sehen."
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: So 19.01.03 17:25 
Sicher kann man das auch so lösen, aber wenn er nicht jeder CheckBox erst zur Laufzeit erstellen will musst du wie folgt vorgehen:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  current: TCheckBox;
begin
  for i := 1 to 10 do
  begin
    case i of
      1: current := CheckBox1;
      2: current := CheckBox2;
      3: current := CheckBox3;
      4: current := CheckBox4;
      5: current := CheckBox5;
      6: current := CheckBox6;
      7: current := CheckBox7;
      8: current := CheckBox8;
      9: current := CheckBox9;
      10: current := CheckBox10;
    end;
    current.State := cbChecked;
  end;
end;


Allerdings bin ich mir nicht sicher, ob es dann noch eine Vereinfachung ist.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 19.01.03 17:30 
@derDoc: Da wäre FindComponent geeigneter, oder?

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: So 19.01.03 18:04 
Also ich gebe mich geschlagen, wenn man es wie Peter sagt macht geht es einfacher. Ich poste deshalb hier den einfachen Code:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  current: TCheckBox;
begin
  for i := 1 to 10 do
  begin
  current := TCheckBox(FindComponent('CheckBox'+IntToStr(i)));
  current.State := cbChecked;
  end;
end;


Wenn jemand noch Vorschläge hat, ich bin für weitere Vereinfachungen offen.

@hansg:
Ich glaube deine Frage ist nun beantwortet.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
hansg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: So 19.01.03 20:25 
Hallo an alle,
jetzt komme ich weiter :D :) :P


Vielen Dank
Hans