-1

Hey all. Ill put this simply.

{assigning 52 jpeg's to 52 different TImages}

What i have:

for x:= 1 to 52 do
case x of
1: img1.picture.loadfromfile(1.jpg);
2: img2.picture.loadfromfile(2.jpg);
3: img3.picture.loadfromfile(3.jpg);
4: img4.picture.loadfromfile(4.jpg);

i think you get the picture.

What i want:

some way of programmatically selecting a certain image using a variable. This could mean filling a string variable with 'img1.picture.loadfromfile(1.jpg)' and then using code to run that, or it could mean something like this..

for x:= 1 to 52 do
img(x).picture.loadfromfile(IntToStr(x)+'.jpg');

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by fayyaz
0
procedure TForm1.Button1Click(Sender: TObject);
Var
    X,I:Integer;
begin
    For X:=1 To 4 do
    Begin
        for I:=0 to Form1.ComponentCount-1 do
        Begin
            if form1.Components[I].Name='Image'+Trim(IntToStr(X)) then
                (form1.Components[I] as TImage).Picture.LoadFromFile(Trim(IntToStr(X))+'.jpg');
        End;
    end
end

;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.