Don't give up easily, friend.
That I very seldom do! - I'm known for my stubborn determination to get my way
Here is a working demo:
Works perfectly (of course)
I personally rarely use exception. But for your case, because you create something in memory, you can't simply exit when exception happens. You should put a try-finally block (see line #64).
As you can tell, I've also avoided the [Try][Except][Finally] - I did consider that a [Finally] might be needed but didn't know not to use [Exit].
I have solved the problem by using a referenced list (array) as a 'look-up' but it's not a perfect solution since that list can be modified by the user without necessarily adding to the resource.
My latest 'trial' code - based again upon your excellent suggestion - though naturally including the extra code needed to complete the task in hand - is:
procedure Rotate(Pic:TImage;Name:string;Angle:single;X,Y:word;T:byte);
Var
tmp, dest : TBGRABitmap;
begin
tmp := TBGRAbitmap.create(Name);
try
try
tmp.LoadFromResource(Name);
except
Form1.MissingImage.Caption := Copy(Name,1,Length(name)-4)+' Image not available';
Form1.MissingImage.Show;
end;
finally
dest := TBGRAbitmap.create;
BGRAReplace(dest, tmp.FilterRotate(PointF(X,Y),angle,true));
dest.ReplaceTransparent(clRed);
Pic.Picture.Clear;
Pic.Picture.Bitmap.SetSize(tmp.Width,tmp.Height);
Pic.Picture.Bitmap.TransparentColor:=clRed;
Pic.Transparent:=true;
dest.Draw(Pic.Picture.Bitmap.Canvas,0,0);
application.ProcessMessages;
dest.free;
tmp.free;
end;
end;
It doesn't trap the missing image - - - well it throws an error when run under the IDE in Debug mode, so I assume that would mean the same directly from the .exe (your comment to run your program from the binary).
I'm obviously missing a 'key' to jumping out of the routine after line 11 : (Form1.MissingImage.Show;) since even though the [Try] may have failed it will continue into the [Finally] section which I only want to happen if the [Try] is successful but I can't (yet) fathom how to accomplish that
I can understand [If][Then][Else] but the [Try]..... is currently defeating my aging grey matter!
. . . . . . . . Just 'thinking' . . . . . . . If I put a boolean [True] in the [Finally] - or somewhere where [Try] has been successful - and use that to determine whether the rest of the code should be executed, would that work ?? . . . . . . more testing needed