I have tried each of the following in Delphi 2010 to display an animated gif on my form. All result in an access violation. (Two of the three variations were commented out on each attempt.) Thanks much.
uses ... GIFImg,... Image1: TImage; procedure TForm1.FormCreate(Sender: TObject); begin // A valid animated gif was loaded into Image1 at design time TGIFImage(image1).Animate := true; TGIFImage(image1.Picture).Animate := true; TGIFImage(image1.Picture.Graphic).Animate := true; end; I attempted to follow the answer in the question linked above, but the solution did not work for me (and with that question being tagged explicitly as Delphi-7, I didn't know if something had changed). Rewriting to "(image1.Picture.Graphic as TGIFImage).Animate := true;" results in "... exception class EInvalidCast with message 'Invalid class typecast'." It's not clear to me why the typecast is invalid since I'm positive that an animated gif has already been loaded at design time.
Edit to clarify the issue, here's the revised code. The showmessage tells me that the image is a TdxSmartImage. No idea why it thinks this. (I did at one point try to load the image into a devExpress control to see if that would work, but I subsequently removed all dexExpress elements from the form/project and regenerated the gif file.
procedure TForm1.FormCreate(Sender: TObject); begin image1.Picture.LoadFromFile('C:\ChronSource\ChronDialogs\11.0 job menu.gif'); ShowMessage(image1.Picture.Graphic.ClassName); // this says "TdxSmartImage" (image1.Picture.Graphic as TGIFImage).Animate := true; end;
TImage. If you are getting an AV on the 3rd variation, you need to debug to find out why. The 1st variation is invalid because aTImageis not aTGIFImage. The 2nd variation is invalid because aTPictureis not aTGIFImage. Those are invalid casts, but you are not using theasoperator to perform the casts, so the compiler doesn't generate any code to check if the casts succeed at runtimeShowMessage(image1.Picture.Graphic.ClassName);tell you?.giffile extension inTPicturesoTdxSmartImagegets priority overTGIFImage. So, either remove that library, or create your ownTGIFImageobject at runtime andAssign()it toimage1.Pictureinstead of callingimage1.Picture.LoadFromFile().