Autor Beitrag
ggehrma
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

WinXP
D2005 Pers.
BeitragVerfasst: So 17.07.05 14:42 
Hallo,

habe folgenden Quelltext:
ausblenden volle Höhe 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:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
begin
  IF chkAlle.Checked = TRUE THEN BEGIN
    chkDll.Checked := TRUE;
    chkExe.Checked := TRUE;
    chkSys.Checked := TRUE;
    chkBmp.Checked := TRUE;
    chkGif.Checked := TRUE;
    chkJpg.Checked := TRUE;
    chkDoc.Checked := TRUE;
    chkPdf.Checked := TRUE;
    chkRtf.Checked := TRUE;
    chkTxt.Checked := TRUE;
    chkXls.Checked := TRUE;
    chkMid.Checked := TRUE;
    chkMp3.Checked := TRUE;
    chkWav.Checked := TRUE;
    chkWma.Checked := TRUE;
    chkAvi.Checked := TRUE;
    chkHtml.Checked := TRUE;
    chkHtm.Checked := TRUE;
    chkPhp.Checked := TRUE;
    chkXml.Checked := TRUE;
    chkSonstige.Checked := TRUE;
  END
  ELSE
  BEGIN
    chkDll.Checked := FALSE;
    chkExe.Checked := FALSE;
    chkSys.Checked := FALSE;
    chkBmp.Checked := FALSE;
    chkGif.Checked := FALSE;
    chkJpg.Checked := FALSE;
    chkDoc.Checked := FALSE;
    chkPdf.Checked := FALSE;
    chkRtf.Checked := FALSE;
    chkTxt.Checked := FALSE;
    chkXls.Checked := FALSE;
    chkMid.Checked := FALSE;
    chkMp3.Checked := FALSE;
    chkWav.Checked := FALSE;
    chkWma.Checked := FALSE;
    chkAvi.Checked := FALSE;
    chkHtml.Checked := FALSE;
    chkHtm.Checked := FALSE;
    chkPhp.Checked := FALSE;
    chkXml.Checked := FALSE;
    chkSonstige.Checked := FALSE;
  END;

Gibt es irgendeine Möglichkeit das Ganze zu verkürzen? Mit Schleifen oder so??

mfg, ggehrma.

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
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 17.07.05 14:47 
Na, Du kannst schonmal die Hälfte sparen, indem Du das so machst
ausblenden Delphi-Quelltext
1:
2:
3:
chkDll.Checked := chkAlle.Checked;
chkExe.Checked := chkAlle.Checked
{...}


Ansonsten sehe ich da keine großen Sparmöglichkeiten. Wenn Du die Checkboxes während der Laufzeit erstellst, kannst Du sie direkt in ein Array packen (siehe FAQs), wenn Du sie zur Entwurfszeit erstellst, bringt Dir das nichts

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 17.07.05 14:52 
Weitere Ansätze:
Die Checkboxen einheitlich benennen, und dann in einer Schleife über Findcomponent.
Ich würde es aber vorziehen, statt der ganzen einzelnen Checkboxen eine Checklistbox einzuführen.

_________________
We are, we were and will not be.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: So 17.07.05 14:55 
Man könnte auch ein GroupBox nehmen, die nur diese CheckBoxes enthält. Dann könnte man alle Child-Komponenten der GroupBox in einer Schleife setzen.
ggehrma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

WinXP
D2005 Pers.
BeitragVerfasst: So 17.07.05 15:04 
Wie genau funktioniert das denn mit den Child-Komponenten? Hab nämlich alle Checkboxen in einer Groupbox.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: So 17.07.05 15:09 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  if groupbox1.ComponentCount > 0 then begin
    for x := 0 to groupbox1.ComponentCount-1 do begin
      (GroupBox1.Components[x] as TCheckBox).checked := True; // oder z.B. den Wert von chkAlle.Checked
    end;
  end;

ungetester Source!
ggehrma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

WinXP
D2005 Pers.
BeitragVerfasst: So 17.07.05 15:24 
ausblenden Delphi-Quelltext
1:
2:
  for x := 0 to grbEndungen.ComponentCount-1 do
    (grbEndungen.Components[x] as TCheckBox).Checked := chkAlle.Checked;

ComponentCount ergibt bei mir leider immer 0. Aber die Checkboxen liegen alle in der GroupBox drin.

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: So 17.07.05 15:33 
Sorry. Habs gerade mal getestet.
So:
ausblenden Delphi-Quelltext
1:
2:
  for x := 0 to grbEndungen.ControlCount-1 do
    (grbEndungen.Controls[x] as TCheckBox).Checked := chkAlle.Checked;

sollte es funktionieren.
ggehrma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

WinXP
D2005 Pers.
BeitragVerfasst: So 17.07.05 15:41 
Super, so funktioniert es. :D Danke.
SQLException
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 89

WinXP + D5 Enterprise
Win2k + D6 Personal
BeitragVerfasst: Mo 18.07.05 15:44 
user profile iconjasocul hat folgendes geschrieben:
Sorry. Habs gerade mal getestet.
So:
ausblenden Delphi-Quelltext
1:
2:
  for x := 0 to grbEndungen.ControlCount-1 do
    (grbEndungen.Controls[x] as TCheckBox).Checked := chkAlle.Checked;

sollte es funktionieren.


dadurch wird die executable aber nicht kleiner, oder?
Tilman
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1405
Erhaltene Danke: 51

Win 7, Android
Turbo Delphi, Eclipse
BeitragVerfasst: Mo 18.07.05 15:57 
user profile iconChristian S. hat folgendes geschrieben:

Ansonsten sehe ich da keine großen Sparmöglichkeiten. Wenn Du die Checkboxes während der Laufzeit erstellst, kannst Du sie direkt in ein Array packen (siehe FAQs), wenn Du sie zur Entwurfszeit erstellst, bringt Dir das nichts


Prinzipiell kann man die Komponenten immer noch im OnCreate ereignis in ein Zeigerarray packen... wenn man viele Zugriffe benötigt bringt das immer noch viel, weil man nur einmal sämtliche Komponenten schreiben muss.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 18.07.05 18:08 
user profile iconSQLException hat folgendes geschrieben:
dadurch wird die executable aber nicht kleiner, oder?

War das gefordert? :gruebel:
Ich denke aber schon. Wer Langeweile hat, kann das ja testen.