Autor Beitrag
Nova
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Fr 27.02.04 20:13 
Hi,
ich habe ein Programm bei dem ca 20. Image Komponenten den gleichen Namen mit nur einer anderen endziffer
Also wie zB
Image1
Image2
...
Image20

jetzt will ich in einer while schleife 1 bis 20 Zählen und die Bilder verändern, möchte aber nicht alle
Komponentennamen einzelnt schreiben. Kann man irgendwie mit einer Zahl arbeiten die in der Schleife
jedesmal erhöht wird, die dann den Komponentennamen auf den zugegriffen werden soll vervollständigt ?
Also etwa so

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
while I <= 20 do
begin
  ('Image' + I).Picture.LoadFromFile ...
  I := I + 1;
end;


Danke schonmal für die Hilfe
-Nova
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Fr 27.02.04 20:24 
Suche in: Delphi-Forum, Delphi-Library FINDCOMPONENT

Das Ergebnis davon kannst du dann als TImage casten.
tmc2004
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

zuviele
D7,D8
BeitragVerfasst: Sa 06.03.04 01:36 
Probiere doch mal dir eine Variable

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var imag:timage
begin
    while I <= 20 do 
    begin 
    imag:='Image'+inttostr(I);
    imag.Picture.LoadFromFile ... 
  I := I + 1; 
end;


oder mit einer for schleife

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var imag:timage
begin
    for I:= 0 to 20 do 
    begin 
    imag:='Image'+inttostr(I);
    imag.Picture.LoadFromFile ... 
  I := I + 1; 
end;


Ist das so in etwa was du machen willst?

Gruß
tmc

Moderiert von user profile iconMotzi: Delphi-Tags hinzugefügt.

_________________
it's not a bug it's a feature
Raphael O.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1596


VS 2013
BeitragVerfasst: Sa 06.03.04 09:29 
obbschtkuche hat dir schon den Suchbegriff gegeben (da so oft auf die Suche verwiesen wird findet man darin auch oft nur wieder scuhaufforderungen, deswegen hier der Code ;) )
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i:=1 to 20 do
begin
 TImage(Findcomponent('Image'+IntToStr(i))).Picture.Loadfromfile ...
end;
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Sa 06.03.04 09:39 
@tmc2004: dein code kann nicht funzen !! oder war das nur ein pseudocode ??

der code von Fiji-Fighter macht genau das was gewünscht ist !

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Nova Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Sa 06.03.04 11:51 
Danke für die Hilfe der Code funzt wunderbar

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
     for i:=1 to 20 do
     begin
          if I <> 3 then
          begin
               A := random( Numbers.count );
               TImage(FindComponent( 'nr' + inttostr(I) ) ).Picture.LoadFromFile( 'images/chip_'+ Numbers[A] +'.ico' );
               Numbers.Delete(A);
          end;
          I := I + 1;
     end;


Danke nochmal :)