Autor Beitrag
sigi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18

Win7 Pro 64bit
Delphi XE5 Prof
BeitragVerfasst: Do 05.01.12 16:52 
Hallo und ein frohes neues Jahr,

angenommen ich habe mehrere TImage (oder Button usw.) und möchte jedes zB. in der Art ansprechen:
ausblenden Delphi-Quelltext
1:
2:
for i := 0 to 10 do
    Image[i].Picture.LoadFromFile(FileListBox1.Items[i]);

was aber so ja nicht geht. Wie kann man die einzelnen ansprechen, ohne haufenweise Code zu schreiben?

Gruß sigi

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8535
Erhaltene Danke: 473

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 05.01.12 16:59 
Möglichkeit 1: Nutze ein Array of TImage (als Variable der Form), dass du im OnCreate der Form so füllst:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
SetLength(MyImageArray, 42);
MyImageArray[0] := Image0;
MyImageArray[1] := Image1;
MyImageArray[2] := Image2;
//..
MyImageArray[41] := Image41;


Möglichkeit 2 (die sich auch mit dem ersten kombinieren lässt): Suche in: Delphi-Forum FINDCOMPONENT.

_________________
We are, we were and will not be.
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Do 05.01.12 17:18 
Wenn die Bilder alle auf einem Panel liegen und sonst keine weiteren Bilder drauf sind gehts auch so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  CompIdx: Integer;
begin
  for CompIdx := 0 to MyPanel.ControlCount -1 do
  begin
    if MyPanel.Controls[CompIdx] is TImage then
      TImage(MyPanel.Controls[CompIdx]).Picture.LoadFromFile(...);  
  end
end;
sigi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18

Win7 Pro 64bit
Delphi XE5 Prof
BeitragVerfasst: Do 12.01.12 16:17 
Danke, mal sehen, ob ich damit als ewiger Anfänger klar komme.

Gruß sigi