Autor Beitrag
1_of_1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi 5
BeitragVerfasst: Di 30.05.06 07:07 
Habe mal wieder ein Problem. Ich möchte eine While-Schleife programmieren, hintereinander verschiedene Labels aufruft und dann mit diesen arbeitet. in etwa so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
while z<10 do
    begin
    if 'a'+z.color=TARGET
    then 'a'+z.color:=Normal;
    z:=z+1;
    end;


dabei sollen nacheinander die Labels a0-a9 aufgerufen werden.
wieg gebe ich das aber nun ein?


Zuletzt bearbeitet von 1_of_1 am Di 30.05.06 07:34, insgesamt 1-mal bearbeitet
chukalv
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 44



BeitragVerfasst: Di 30.05.06 07:25 
IMHO this should work... Haven`t delphi here so can`t test it...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var
  Found: Boolean;
  i,z: integer;
  TempComp: TComponent;
begin
for z := 0 to 10 begin
for i := 0 to ComponentCount - 1 do begin
 if LowerCase(Components[i].Name) = LowerCase(a+inttostr(z)) then begin
      TempComp := Components[i];
      Found := TempComp is TLabel;
    end;
    if Found then break;
  end;
if Found then if (TempComp as TLabel).color = TARGET then (TempComp as TLabel).color = Normal;

end;
end;
1_of_1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi 5
BeitragVerfasst: Di 30.05.06 07:34 
Sorry, das da oben funktioniert bei mir nicht. Vielleicht könntest du die wichtigsten Schritte mal kurz erklären?

Kann man das ncht einfacher programmieren, etwa sso, wie oben mit einer Zählvariable?
chukalv
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 44



BeitragVerfasst: Di 30.05.06 07:45 
Sorry, some little mistakes. Now tested on Delphi and it works...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var
  Found: Boolean;
  i,z: integer;
  TempComp: TComponent;
begin
for z := 0 to 9 do begin       // for 'a0' to 'a9'
for i := 0 to ComponentCount - 1 do begin   //surf throught al the components
 if LowerCase(Components[i].Name) = LowerCase('a'+inttostr(z)) then begin
      TempComp := Components[i];
      Found := TempComp is TLabel;   // if a component a+z (a0..a9) found
    end;
    if Found then break;
  end;
if Found then if (TempComp as TLabel).color = TARGET then (TempComp as TLabel).color := Normal; //don`t know what have You meant with the TARGET and Normal colors, but with other parametres this code works..

end;
end;
1_of_1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi 5
BeitragVerfasst: Di 30.05.06 07:59 
Bei mir geht es noch nicht so ganz (Delphi 5).
1. Undefinierter Bezeichner ComponentCount
2. Undefinierter Bezeichner Component
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Di 30.05.06 08:02 
Schau mal nach FindComponent das sollte sein was Du suchst.
1_of_1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi 5
BeitragVerfasst: Di 30.05.06 08:10 
:idea: Ja! Genau das war's, was ich gesucht hatte! :idea:
Trozdem auch danke an chukalv für seine Geduld mit mir. :wink: