Autor Beitrag
Quake User
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 159



BeitragVerfasst: Di 06.12.05 11:31 
Ich verwende in einem Formular mehrere Checkboxen.
wie kann ich diese elegant verwalten (laden, speichern, setzen)

Um alle zu aktivieren kann ich bspw. folgendes schreiben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure AllesAnClick;
begin
  with Form1 Do
  begin
    CheckBox1.Checked:= true;
    CheckBox2.Checked:= true;
    ...
    CheckBox40.Checked:= true;
   end;
end;


das geht doch sicher besser. ?

Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Di 06.12.05 11:56 
Guckst du hier oder hier
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Di 06.12.05 11:56 
Hallo,

schau Die einmal in der Delphi-Hilfe ControlCount und Controls an. Für obiges Problem kannst Du es folgendermassen machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure AllesAnClick; 
var i:Integer;
begin 
  with Form1 do
  begin
    for i:=0 to ControlCount-1 do 
     if (Controls[i] is TCheckBox) then TCheckBox(Controls[i]).Checked:=True;
  end; // with
end; // AllesAnClick

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
Quake User Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 159



BeitragVerfasst: Di 06.12.05 12:25 
user profile iconsmiegel hat folgendes geschrieben:
Hallo,

schau Die einmal in der Delphi-Hilfe ControlCount und Controls an. Für obiges Problem kannst Du es folgendermassen machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure AllesAnClick; 
var i:Integer;
begin 
  with Form1 do
  begin
    for i:=0 to ControlCount-1 do 
     if (Controls[i] is TCheckBox) then TCheckBox(Controls[i]).Checked:=True;
  end; // with
end; // AllesAnClick


Vielen Dank - Das ist eine Variante.

Ich dachte als erstes an ein Array of TCheckBox oder eine Klasse. Will ich Bspw. den Status aller CheckBoxen vom Typ1 speichern funktioniert deine Idee nicht. (funktioniert nur wenn ich alle CheckBoxen speichere,ändere...)
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 06.12.05 15:36 
hallo,
user profile iconQuake User hat folgendes geschrieben:
Will ich Bspw. den Status aller CheckBoxen vom Typ1 speichern funktioniert deine Idee nicht. (funktioniert nur wenn ich alle CheckBoxen speichere,ändere...)

Dann prüf doch in einer Abfrage, ob die Checkbox vom Typ1 ist :gruebel:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Quake User Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 159



BeitragVerfasst: Mi 07.12.05 00:03 
user profile iconsmiegel hat folgendes geschrieben:
Hallo,

schau Die einmal in der Delphi-Hilfe ControlCount und Controls an. Für obiges Problem kannst Du es folgendermassen machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure AllesAnClick; 
var i:Integer;
begin 
  with Form1 do
  begin
    for i:=0 to ControlCount-1 do 
     if (Controls[i] is TCheckBox) then TCheckBox(Controls[i]).Checked:=True;
  end; // with
end; // AllesAnClick



Die Procedur durchläuft nur die Elemente, die direkt auf der Form liegen (Also Panel1, Panel2 usw.) aber nicht die Elemente, die auf den Panels liegen (Also CheckBox1 usw.)

Ich habe in der Hilfe auch nicht die Lösung dafür gesehen.
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Mi 07.12.05 07:30 
Hallo,

für ein Panel kannst Du meinen Code auch benutzen. Du musst nur Form1 durch den Namen des Panels ersetzen.

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Mi 07.12.05 07:41 
Warum nimmst du nich TCheckListBox

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
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: Mi 07.12.05 08:26 
Hallo,
user profile iconQuake User hat folgendes geschrieben:
Die Procedur durchläuft nur die Elemente, die direkt auf der Form liegen (Also Panel1, Panel2 usw.) aber nicht die Elemente, die auf den Panels liegen (Also CheckBox1 usw.)

wenn Du alle Elemente durchlaufen willst, kannst du die Eigenschaft Components verwenden.
user profile iconDelphi-Hilfe hat folgendes geschrieben:
Mit Components können Sie auf alle der Komponente untergeordneten Komponenten zugreifen, beispielsweise auf die Steuerelemente eines Formulars. Die Eigenschaft ist besonders nützlich, wenn Sie nicht einzelne untergeordnete Komponenten, sondern die Komponenten in ihrer Gesamtheit ansprechen wollen.

Ein Beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var z : Integer;
begin
  for z := 0 to ComponentCount-1 do
    if Components[z] is TCheckBox then
      begin
      if TCheckBox(Components[z]).Parent = Form1 then
        Memo1.Lines.Add(TCheckBox(Components[z]).Name);
      if TCheckBox(Components[z]).Parent = Panel1 then
        Memo2.Lines.Add(TCheckBox(Components[z]).Name);
      if TCheckBox(Components[z]).Parent = Panel2 then
        Memo3.Lines.Add(TCheckBox(Components[z]).Name);
      end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )