Autor Beitrag
brto
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Di 08.07.03 08:04 
Warum funzzt das nicht?
defaultname : string;
defaultname:='wasauchimmer';

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
for i:= 1 to 43 do
   begin
       with TCheckBox(FindComponent(defaultname + IntToStr(i)) do
        begin
        if checked = true then
           begin
            form1.caption := 'toll';
           end;
        end;
end;


Es kommt kein Fehler beim Compilieren, nur wenn es läuft kommt nen Problem bei if checked = true then

Danke

Moderiert von user profile iconUGrohne: Delphi-Tags hinzugefügt
foxy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 814

Ubuntu, Gentoo
C++, PHP, Java, Ruby, Perl (Eclipse)
BeitragVerfasst: Di 08.07.03 08:17 
es heist ja auch
ausblenden Delphi-Quelltext
1:
 if checkbox1.checked then					


checked gibt ja schon einen boolschen wert zurück

_________________
"Only wimps use tape backup: real men just upload their important stuff on ftp, and let the rest of the world mirror it." (Linus Torvalds)
OperatingSystem Laptop (Ubuntu Hardy)
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Di 08.07.03 08:33 
foxy hat folgendes geschrieben:
es heist ja auch
ausblenden Delphi-Quelltext
1:
 if checkbox1.checked then					


checked gibt ja schon einen boolschen wert zurück


er hat aber ein with davor, das ist schon so ok.

Ich kann keinen fehler im quellcode sehen (bis auf eine vergessene ) bei der with-anweisung, also wirds auch nicht der Originale Quelltext sein.


Zitat:

nur wenn es läuft kommt nen Problem bei if checked = true

klasse aussage, da weiß jeder sofort welches.
Problem könnte sein, daß es eine der Checkboxen gar nicht gibt, daher evtl mal vorher auf Nil prüfen, ob es die Komponente wirklich gibt.

edit:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Button1Click(Sender: TObject);
Var i:integer;
    tempComp:Tcomponent;
begin
  for i:= 1 to 6 do
    begin
      tempcomp := FindComponent('checkbox' + IntToStr(i));
      if tempcomp<>NIl then
       with TCheckBox(tempcomp) do
        begin
          if checked = true then
            begin
              form1.caption := 'toll';
            end;
        end;
    end;
end;


Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Di 08.07.03 12:01 
@foxy
ob du nun test = True oder einfach nur test bei einer if abfrage machst, das ist egal. das fürht beides zum selben ergbnis

_________________
MFG
Michael Springwald, "kann kein englisch...."
DataCool
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112



BeitragVerfasst: Di 08.07.03 14:23 
Hi,

ich gehe mal davon aus, das Du den Code dazu benutzen willst, um dynamisch erzeugte Komponenten anzusprechen ?!

Hast Du schon einmal überprüft, ob die Checkboxen wirklichen so heisen :?:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button2Click(Sender: TObject);
Var i : Longint;
    comp : TWinControl;
begin
  for i:= 0 to form1.ComponentCount - 1 do begin
    if form1.Components[i] is TWinControl then begin
      comp := TWinControl(form1.Components[i]);
      ShowMessage(comp.Name);
    end;
  end;
end;


Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.

_________________
DataCool