Sorry even though I've been at this a while I'm still a bit of a n00b - I don't really understand what you mean by unprotected casts.
Anyway, I should have explained more clearly. I have a number of screens that the user can click through, and I am trying to create a back button here. Each screen has a series of varying objects like text fields, list boxes and various image choices. The user chooses which image is visible by clicking on various buttons. Only one image is visible at a time. The different screens can be reused for various purposes, so I need to store all the user-changeable data on each screen, so that it can be restored back to its former state when the user clicks the back button. I have various string/int arrays that store the data in the other fields, and that all seems to work fine. The question here is purely about storing which image is visible.
ObjectAVar is a global variable of TComponent that saves the name of the currently visible image. There is also a corresponding array of TComponent, called ObjectA, so when the user changes screen, a new line gets created in the TComponent array and ObjectAVar is saved there.
So, the code on the user screen for selecting Image1 will be something like this:
begin
// code here to hide all other images, then ...
Image1.Visible :=true;
ObjectAVar :=Image1;
end
It gets put into the ObjectA array when the user goes to a new screen.
Then in the back button, when we return to this screen, we'll fetch the correct visible image from the ObjectA array, then show that image:
begin
// code here to hide all other images, then ...
ObjectAVar := ObjectA[High(ObjectA)];
TImage(ObjectAVar).Visible :=true;
Having tried it, this works. So I'm just a bit confused what all the other code in your example was about, and whether I've missed something crucial by making mine so simple. Thanks !