I use a timage in a form which load a background image. The problem is when i choose another picture in run time and change it by Img_Bk.Picture.LoadFromFile( SaveFileName ); It doesnt work (Picture did n't change ). I mean it shows previous picture and doesn't show the new image during run time. Id like to change application background image during run time in my company by users which main form is a mdi form . I use delphi 7 .
try
Img_Bk.Picture := nil ;
if FileSize > 100 then
begin
Img_Bk.Picture.LoadFromFile( SaveFileName );
end;
Img_Bk.Stretch := True ;
except
end;
LoadFromFile
is known to work. So there must be a more prosaic explanation.The first possible explanation is that
FileSize
is not greater than 100 and the if condition evaluates false.Another possible explanation is that the image in the file that you specify is not the one you are expecting.
Otherwise, your code has a swallow all exception handler. And so when the call to
LoadFromFile
fails and raises an exception, your code ignores that and carries on as if nothing un-toward had happened. Remove the try/except, and deal with the error that will be revealed.The real lesson for you to learn is never to write such an exception handler again.
This program should prove to you that
LoadFromFile
is just fine: