-3

i tried the solution suggested here in delphi 2010 and XE7

How to use Animated Gif in a delphi form

both of them raise exception with the following message

"Exception class EInvalidCast with message 'Invalid class typecast'."

Community
  • 1
  • 1
Alireza
  • 11
  • 2
  • 5
  • Please show your code. It should work in normal circumstances, so we need some relevant information from you. – GolezTrol Feb 15 '15 at 09:35

2 Answers2

1

The code you refer to is:

(Image1.Picture.Graphic as TGIFImage).Animate := True;

The error message indicates that the checked as cast fails. Which means that Image1.Picture.Graphic does not descend from TGIFImage. Whatever you put into the image control, it would appear not to be a GIF image.

I realise that this answer does not give you precise steps to a working program. However, I believe that the first step is to understand what the error message means. Once you understand that you know where to look for the solution.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • You need to put a `TGIFImage` into the `TImage` before you can then cast the `Graphic` to a `TGIFImage`, eg: `gif := TGIFImage.Create; Image1.Picture.Assign(gif); ... (Image1.Picture.Graphic as TGIFImage).Animate := True;` or `Image1.Picture.LoadFromFile('image.gif'); (Image1.Picture.Graphic as TGIFImage).Animate := True;` Either way, make sure `GIFImg` is in your `uses` clause. – Remy Lebeau Feb 15 '15 at 17:22
  • @Remy The doesn't compile without GIFImg in the uses clause – David Heffernan Feb 15 '15 at 17:33
  • I stated as much in my last comment. – Remy Lebeau Feb 16 '15 at 09:34
  • @Remy My point is that we already know that GIFImg is in the uses clause because we know that the code has compiled – David Heffernan Feb 16 '15 at 09:38
0

The problem was from the components. In Delphi 2010 Graphic class was changed to TJvGIFImage by JEDI VCL and on XE7 Graphic class was changed to TdxSmartImage by devExpress.after I removed the related packages from install packages the problem solved.

Thanks for your help.

Alireza
  • 11
  • 2
  • 5
  • This is not an answer to the question you asked. – David Heffernan Feb 15 '15 at 15:26
  • I'm confused, your question had no mention that you were using any of this. – Jerry Dodge Feb 15 '15 at 15:42
  • @Jerry-Dodge I didn't think that components may cause this problem. In addition on d2010 only JEDI is installed and on XE7 only Devexpress. so i thought that something is wrong with the delphi. – Alireza Feb 16 '15 at 08:21
  • @david-heffernan I don't know how to explain, as I understand JEDI changes TImage.Picture property from TGIFImage to TJvGIFImage. when delphi wants to compile this line `Image1.Picture.Graphic as TGIFImage` becuase the left and right side are in different type(the left side is TJvGiFImage and the right side is TGIFImage ) raise "Invalid class typecast" Exception. here is the ticket about this problem on devexpress support center. [link](https://www.devexpress.com/Support/Center/Question/Details/Q562011) – Alireza Feb 16 '15 at 08:50
  • Yes. It's exactly as I said in my answer. The question makes no mention of 3rd party libraries. – David Heffernan Feb 16 '15 at 08:53