1

Following my previously asked question; How do I display two images consecutively like a gif?, I was told that I could create a gif.

Here is my reason: tspeedbutton does not accept .gif extension for me.

How can I add this?

btnNotification.Glyph.LoadFromFile(ICON_DIR + '/notification-active.gif');

I googled but couldn't find documentation because of Delphi.

Hello,

Actually i am trying to create Notification button. If there is no notification, its image is notification.bmp but if there is notification, it should be gif on tspeedbutton. I added a timer and polling the server, is there any notification for me ? in every 6 seconds, if yes i need to change bmp image to gif on tspeedbutton

Mike Torrettinni
  • 1,816
  • 2
  • 17
  • 47
Nevermore
  • 1,663
  • 7
  • 30
  • 56

1 Answers1

1

to do this in a clean way I recommend that you build a new component. luckily there is a component that is a TSpeedButton and accepts any type of TPicture as its Glyph property, all what we have to do is to modify it to animate the Glyph if it was a GIF

So copy the unit of the TNCRSpeedButton from the accepted answer here

go to the following procedure and add the lines to the code (or just replace this procedure with that one).

procedure TNCRSpeedButton.GlyphChanged(Sender: TObject);
begin
  if (FGlyph.Graphic <> nil) and (not FGlyph.Graphic.Empty) then
  begin
    FGlyphCoordinates.OnChange := nil; // Prevent multiple invalidates
    FGlyphCoordinates.X := (Width - FGlyph.Graphic.Width) div 2;
    FGlyphCoordinates.Y := (Height - FGlyph.Graphic.Height) div 2;
    FGlyphCoordinates.OnChange := CoordinatesChanged;
///// add these lines here ///////////////////////////////////
    if (FGlyph.Graphic is TGifImage) then
      begin
      (FGlyph.Graphic as TGifImage).Animate := True;
      end;
//////////////////////////////////////////////////////////////
  end;
  Invalidate;
end;

now the component when recieved a TGIFImage as its Glyph it will animate it.

Nasreddine Galfout
  • 2,550
  • 2
  • 18
  • 36
  • to the down voter the accepted answer is mine and I'm the author of `TNCRSpeedbutton`, I just pratically gave the OP a peice of pie on a golden plate, all the Info is still on SO, so this does not violets any rule, What is wrong with my answer?. – Nasreddine Galfout Dec 23 '17 at 16:28