Autor Beitrag
speck12
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Mo 24.12.07 20:11 
Hallo miteinander!
Ich habe 8 checkboxen, 8 Edit-Felder und 8 Colorboxen. Ist eine checkbox aktiviert, so soll das entsprechende Edit-feld samt Colorbox auch aktiviert sein. Nur finde ich es ziemlich unübersichtlich, jedes mal die gleiche Prozedur zu schreiben und nur die Zahlen umzuändern.
Ich bin mir sicher, es gibt irgendeine Möglichkeit, folgende 8 Prozeduren zu einer zusammenzufasse.

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:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
procedure TForm1.CheckBox1Click(Sender: TObject);
  begin
   if checkbox1.Checked = false then
    begin
     TermEdit1.Enabled := false;
     ColorBox1.Enabled := false;
    end
   else
    begin
     TermEdit1.Enabled := true;
     ColorBox1.Enabled := true;
    end;
  end;

procedure TForm1.CheckBox2Click(Sender: TObject);
  begin
   if checkbox2.Checked = false then
    begin
     TermEdit2.Enabled := false;
     ColorBox2.Enabled := false;
    end
   else
    begin
     TermEdit2.Enabled := true;
     ColorBox2.Enabled := true;
    end;
  end;

procedure TForm1.CheckBox3Click(Sender: TObject);
  begin
   if checkbox3.Checked = false then
    begin
     TermEdit3.Enabled := false;
     ColorBox3.Enabled := false;
    end
   else
    begin
     TermEdit3.Enabled := true;
     ColorBox3.Enabled := true;
    end;
  end;

procedure TForm1.CheckBox4Click(Sender: TObject);
  begin
   if checkbox4.Checked = false then
    begin
     TermEdit4.Enabled := false;
     ColorBox4.Enabled := false;
    end
   else
    begin
     TermEdit4.Enabled := true;
     ColorBox4.Enabled := true;
    end;
  end;


procedure TForm1.CheckBox5Click(Sender: TObject);
  begin
   if checkbox6.Checked = false then
    begin
     TermEdit5.Enabled := false;
     ColorBox5.Enabled := false;
    end
   else
    begin
     TermEdit5.Enabled := true;
     ColorBox5.Enabled := true;
    end;
  end;

procedure TForm1.CheckBox6Click(Sender: TObject);
  begin
   if checkbox5.Checked = false then
    begin
     TermEdit6.Enabled := false;
     ColorBox6.Enabled := false;
    end
   else
    begin
     TermEdit6.Enabled := true;
     ColorBox6.Enabled := true;
    end;
  end;

procedure TForm1.CheckBox7Click(Sender: TObject);
  begin
   if checkbox7.Checked = false then
    begin
     TermEdit7.Enabled := false;
     ColorBox7.Enabled := false;
    end
   else
    begin
     TermEdit7.Enabled := true;
     ColorBox7.Enabled := true;
    end;
  end;

procedure TForm1.CheckBox8Click(Sender: TObject);
  begin
   if checkbox8.Checked = false then
    begin
     TermEdit8.Enabled := false;
     ColorBox8.Enabled := false;
    end
   else
    begin
     TermEdit8.Enabled := true;
     ColorBox8.Enabled := true;
    end;
  end;


Würde mich über Vorschläge freuen.
Allen ein schönes Fest
Mfg
LorenzS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128

MS-DOS, WIN 7, WIN 10
BP7.0, D3, D5
BeitragVerfasst: Mo 24.12.07 20:35 
so in der art?
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:
27:
procedure Makeit(lCheckBox:TCheckBox;lTermEdit:TTermEdit;lColorBox:TColorBox);
begin
 if lCheckBox.Checked = false then 
 begin 
  lTermEdit.Enabled := false; 
  lColorBox.Enabled := false; 
 end 
 else 
 begin 
  lTermEdit.Enabled := true; 
  lColorBox.Enabled := true; 
 end;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
 Makeit(checkbox1,TermEdit1,ColorBox1);
end;
procedure TForm1.CheckBox2Click(Sender: TObject);
begin
 Makeit(checkbox2,TermEdit2,ColorBox2);
end;
....
procedure TForm1.CheckBox8Click(Sender: TObject);
begin
 Makeit(checkbox8,TermEdit8,ColorBox8);
end;
speck12 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Mo 24.12.07 21:17 
hmm, eigentlich hab ich da eher an insgesamt nur eine prozedur gedacht, die den Sender erkennt und dementsprechend die richtigen felder de-/aktiviert.
mfg
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Mo 24.12.07 21:18 
was du brauchst nennt sich formcomponent
speck12 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Mo 24.12.07 21:24 
"formcomponent", was genau ist das?
Mit der Suche kommm ich nur auf meinen Thread..
mfg
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Mo 24.12.07 21:24 
user profile iconJann1k hat folgendes geschrieben:
was du brauchst nennt sich formcomponent

Dicht drann, aber es heißt 'FindComponent'.

_________________
Na denn, dann. Bis dann, denn.
speck12 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Mo 24.12.07 21:26 
ah, ok ^^
dazu findet sich auch einiges in der Delphihilfe. Dankeschön, werde es mal damit probieren und dann bescheid geben.
Mfg
speck12 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Di 25.12.07 00:28 
also ich habe es jetzt mit "FindComponent" versucht, klappt allerdings nicht.
Alle Komponenten, also checkboxen, edit-felder und colorboxen befinden sich auf einem panel.
Hier der Code
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:
27:
28:
29:
procedure TForm1.Panel3Click(Sender: TObject);
 var sender_name, term_name, color_name,temp : String;
     i : Integer;
     c : Char;
  begin
   sender_name := 'CheckBox';
   term_name   := 'TermEdit';
   color_name  := 'ColorBox';
    begin
     If Sender is TCheckbox then
      begin
       temp := TCheckbox(Sender).Name;
       i := StrToInt(temp[9]);
       edit1.Text := IntToStr(i);
       if TCheckbox(Sender).Checked = false
        then
         begin
          TTermEdit(FindComponent(term_name + IntToStr(i))).Enabled  := false;
          TColorBox(FindComponent(color_name + IntToStr(i))).Enabled := false;
         end;
       if TCheckbox(Sender).Checked = true
        then
         begin
          TTermEdit(FindComponent(term_name + IntToStr(i))).Enabled  := true;
          TColorBox(FindComponent(color_name + IntToStr(i))).Enabled := true;
         end;
     end;
    end;
  end;


Ich bin mir aber nicht sicher, ob da als Sender tatsächlich eine checkbox übertragen wird, da ich es alles über das OnClick des Panels mache. (Ich weiß nicht, wo ich es sonst hinpacken soll)
Bin etwas verwirrt
mfg
DrRzf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 260

Win XP Prof
D7 Enterprise
BeitragVerfasst: Di 25.12.07 01:33 
müsste es nicht heissen ?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
  temp := (Sender as TCheckbox).Name;  
  i := StrToInt(temp[9]);  
  edit1.Text := IntToStr(i);  
  if (Sender as TCheckbox).Checked = false


was sagt der debugger ?
wird temp noch richtig gesetzt ? gibts ne fehlermeldung ?

Edit:
Wenn du das onklick des Panels auswertest, wird er dir auch nie die if bedingung erfüllen da der Sender dann das panel und nicht die checkbox ist.

ausblenden Delphi-Quelltext
1:
If Sender is TCheckbox then					

_________________
rein statistisch gesehen darf man keiner statistik trauen die man nicht selbst gefälscht hat.
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Di 25.12.07 02:27 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
was du brauchst nennt sich formcomponent


Dicht drann, aber es heißt 'FindComponent'.


War anscheinend irgendwie spät... :rofl:
Zorro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 76

Win 2000, Win XP Pro
Delphi 7 Architect
BeitragVerfasst: Di 25.12.07 04:26 
user profile iconspeck12 hat folgendes geschrieben:
Nur finde ich es ziemlich unübersichtlich, jedes mal die gleiche Prozedur zu schreiben und nur die Zahlen umzuändern.
Ich bin mir sicher, es gibt irgendeine Möglichkeit, folgende 8 Prozeduren zu einer zusammenzufasse.
[snip]
Würde mich über Vorschläge freuen.
Allen ein schönes Fest
Mfg


Gibbet eine Reihe von Möglichkeiten:
- Du kannst über den Sender-Parameter gehen
- Du kannst den Tag benutzen
- Findcomponent (wurde schon beschrieben)
- (auch wenn für deinen Fall eher unpraktisch, aber grundsätzlich: ) Auch Komponenten-Arrays sind möglich.

Greetz
Zorro
speck12 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Di 25.12.07 11:55 
welche Prozedur oder welches Ereignis sollte ich denn nehmen, damit der Sender eine Checkbox ist? Gibt es eine Möglichkeit eine allgemeine TCheckbox.OnClick prozedur zu schreiben, in der dann der Sender ermittelt wird?
Das FindComponent nutze ich ja dann zur Zuweisung der anderen Komponenten.
Mfg
speck12 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Di 25.12.07 13:03 
So, endlich habe ich es geschafft :D !
Ich habe einfach alle Checkboxen markiert und dann auf ein OnClick-Ereignis geklickt und folgende Prozedur geschrieben.
Klappt alles wunderbar und ist viel übersichtlicher.
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:
procedure TForm1.CheckBox1Click(Sender: TObject);
var term_name, color_name,temp : String;
    i,n : Integer;
 begin
  term_name   := 'TermEdit';
  color_name  := 'ColorBox';
  temp := (Sender as TCheckBox).Name;
  n := Length(temp);
  i := StrToInt(temp[n]);
  edit1.Text := IntToStr(i);
   if (Sender as TCheckbox).Checked = false
    then
     begin
      TTermEdit(FindComponent(term_name + IntToStr(i))).Enabled  := false;
      TColorBox(FindComponent(color_name + IntToStr(i))).Enabled := false;
     end;
   if (Sender as TCheckbox).Checked = true
    then
     begin
      TTermEdit(FindComponent(term_name + IntToStr(i))).Enabled  := true;
      TColorBox(FindComponent(color_name + IntToStr(i))).Enabled := true;
     end;
 end;


Danke allen, die geschrieben haben
Mfg
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Di 25.12.07 13:53 
Geht sogar noch kürzer und effizienter:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.CheckBox1Click(Sender: TObject);
var
  c: TCheckBox;
  i: Integer;
begin
  c := Sender as TCheckBox;
  i := StrToInt(c.Name[Length(c.Name)]);
  Edit1.Text := IntToStr(i);
  TTermEdit(FindComponent('TermEdit' + IntToStr(i))).Enabled := c.Checked;
  TColorBox(FindComponent('ColorBox' + IntToStr(i))).Enabled := c.Checked;
end;