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');

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

;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.