Autor Beitrag
Flash106
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: Di 16.11.04 18:33 
Hallo..

ich habe ein formular mit ca. 30 checboxen. Per code sollen diese angeklickt werden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
for j:=1 to Form.ComponentCount - 1 do
begin
  begin
    komponente := Form.Components[j];
      if (komponente is TCheckBox) then
        (komponente as TCheckBox).Checked := true;
        //TCheckbox(komponente).Checked := true; //<-- das klappt auch nicht :(
    end;
end;


... es klappt nich :( ... krieg nen listenindex fehler :( ... es klappt NUR bei checkboxen nicht.. bei allen anderen komponenten auf dem form schon :( ...

Bitte um Hilfe.

Bianca

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
Moderiert von user profile iconTino: Topic aus Sonstiges verschoben am Mi 17.11.2004 um 10:39
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Di 16.11.04 18:56 
Als was hast du denn Komponente deklariert? Hast du noch andere Komponenten auf dem Formular außer CheckBoxen?

Gruß,
Jörg

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: Di 16.11.04 19:05 
na komponenten ist als TComponent deklariert und ja es sind noch andere koms auf dem form. edit felder.. datepicks.. sowas.. mit denen funktioniert alles super.. nur nich mit den checkboxen...
:cry:
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Di 16.11.04 19:12 
mmh..listenindex fehler

kann es sein, dass du im OnClick Der CheckBox irgendwas machst (was zu diesem Zeitpunkt noch nicht bereit ist)
das Problem ist nämlich, das bei der normalen CheckBox das OnClick auch ausgelöst wird, wenn du den State per Code änderst.

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: Di 16.11.04 19:17 
ja natürlich!! das ist es DANKE!!... aber jetz benötige ich noch eine lösung dieses problem... :( .. irgendwelche ideen??
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Di 16.11.04 19:23 
Na einfach ausschalten:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var
  proc : TNotifyEvent;
begin
  //und dann in der Schleife
  proc:=TCheckBox(komponente).OnClick;
  TCheckBox(komponente).OnClick:=nil;
  //virtueller Klick hier
  TCheckBox(komponente).OnClick:=proc;

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Di 16.11.04 19:24 
Entweder über ein globales Flag, das innerhalb der OnClick-Events ausgewertet wird oder aber die OnClick-Events kurzfristig "deaktivieren":

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var
  aOldOnClick: TNotifyEvent;

for j := 0 to Form.ComponentCount - 1 do
begin
  komponente := Form.Components[j];
  if (komponente is TCheckBox) then
    // ein Typecast per as ist überflüssig, da wir ja schon selbst per is geprüft haben!
    with TCheckBox(komponente) do
    begin
      aOldOnClick := OnClick;
      OnClick := nil;
      Checked := True;
      OnClick := aOldOnClick;
    end;
  end;
end;

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Flash106 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 234


D7 Ent
BeitragVerfasst: Di 16.11.04 19:29 
das mit dem flag fine ich interessant. kann mir das mal jemand erklären?? =) danke... super antworten! =) *freu*
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Di 16.11.04 19:43 
nimm am Besten gleich ne prozedur damit du das bei allen cb's machen kannst
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure SetCheckBox(CheckBox: TCheckBox; Checked: boolean);
var
 Temp: TNotifyEvent;
begin
 Temp := CheckBox.OnClick;
 CheckBox.OnClick := nil;

 CheckBox.Checked := Checked;

 CheckBox.OnClick := Temp;
end;

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)