Autor Beitrag
cscp
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 49



BeitragVerfasst: So 23.01.05 17:53 
hallo,
wie schaffe ich es die anzahl der aktivierten checkboxen in einem form zu ermitteln... ohne lästige schreibarbeit da es einige checkboxen sind..
danke
herzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 168

WINXP pro, SUSE Linux 9.0
D7 Pers.
BeitragVerfasst: So 23.01.05 18:12 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
var
  i:integer;
begin
  for i:=0 to self.ControlCount-1 do
    if self.Controls[i].ClassType=TCheckBox then
      if TCheckbox(self.Controls[i]).Checked= true then
        Showmessage(self.Controls[i].Name);
end;


mfg herzi
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: So 23.01.05 18:13 
Hi,

das geht ganz wunderbar mit Hilfe der Eigenschaften ComponentsCount und Components von TForm und der Methode InheritsFrom von Components:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var
  i, c: Integer;
begin
  c := 0;
  for i := 0 to Form1.ComponentCount-1 do  // Alle Elemente auf der Form durchlaufen
  begin
    if Form1.Components[i].InheritsFrom(TCheckBox) then   // Ist es eine CheckBox?
      Inc(c);
  end;
  ShowMessage(IntToStr(c));
end;


Gruß,
raziel

_________________
JSXGraph
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 23.01.05 18:16 
Nicht ganz, raziel! Er will nur die Anzahl der aktivierten:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  i, c: Integer;  
begin  
  c := 0;  
  for i := 0 to Form1.ComponentCount-1 do  // Alle Elemente auf der Form durchlaufen  
  begin  
    if Form1.Components[i].InheritsFrom(TCheckBox) then   // Ist es eine CheckBox?  
      if (Form1.Components[i] as TCheckBox).Checked then
        Inc(c);  
  end;  
  ShowMessage(IntToStr(c));  
end;


AXMD