As mentioned in my coment you can create an array of TJPEGImage objects to store the images.
You do this like so:
//Global array for storing images
var Images: Array [1..26] of TJPEGImage;
implemenetation
...
procedure TForm1.FormCreate(Sender: TObject);
var I: Integer;
begin
for I := 1 to 26 do
begin
//Since TJPEGIMage is a class we first need to create each one as array only
//stores pointer to TJPEGImage object and not the object itself
Images[I] := TJPEGImage.Create;
//Then we load Image data from file into each TJPEGImage object
//If file names are not numerically ordered you would probably load images
//later and not inside this loop. This depends on your design
Images[I].LoadFromFile('D:\Image'+IntToStr(I)+'.jpg');
end;
end;
As you see in source coments the array only stores pointers to TJPEGImage objects and not the TJPEGImage objects themself. So don't forget to create them before trying to load any image data to them. Failing to do so will result in Access Violation.
Also becouse you have created these TJPEGImage objects by yourself you also need to free them by yourself to avoid posible memory leaks
procedure TForm1.FormDestroy(Sender: TObject);
var I: Integer;
begin
for I := 1 to 26 do
begin
Images[I].Free;
end;
end;
In order to show these stored images in your TImage component use this
//N is array index number telling us which array item stores the desired image
Image1.Picture.Assign(Images[N]);
Second approach that you can use
Now since TJPEGImage are classed objects you could also use TObjectList to store pointers to them.
In such case creation code would look like this
procedure TForm1.FormCreate(Sender: TObject);
var I: Integer;
Image: TJPEGImage;
for I := 1 to NumberOfImages do
begin
//Create TObject list with AOwnsObjects set to True means that destroying
//the object list will also destroy all of the objects it contains
//NOTE: On ARC compiler destroying TObjectList will only remove the reference
//to the objects and they will be destroyed only if thir reference count
//drops to 0
Images := TObjectList.Create(True);
//Create a new TJPEGImage object
Image := TJPEGImage.Create;
//Load image data into it from file
Image.LoadFromFile('Image'+IntToStr(I)+'.jpg');
//Add image object to our TObject list to store reference to it for further use
Images.Add(Image);
end;
end;
You would now show these images like so
//Note becouse first item in TObject list has index of 0 you need to substract 1
//from your ImageNumber
Image1.Picture.Assign(TJPEGImage(Images[ImageNumber-1]));
Since we set TObjectList to own our TJPEGImage objects we can quickly destroy all of them like so
//NOTE: On ARC compiler destroying TObjectList will only remove the reference
//to the objects and they will be destroyed only if thir reference count
//drops to 0
Images.Free;
TImageList
in this case to store (hi-res?) images (not icons). create and use genericTObjectList<TImage>
instead. – teranarrPics : array[1..26] of TJPEGImage;
how do I add the images to it? I have tried loading the location names(string) into the array but it ain't working. – GerhardAA