Glyph TAnimation Component

Description

TAnimation is an encapsulation of the Windows animation common control. It plays so called “silent” AVIs (animation files), as you can see when copying or deleting multiple files or when you are searching for files.

To load an animation, you give the property Animation the file name of the .avi file or the name of an AVI resource. The internal resources can also be selected with the property Resource.

To play an animation, you must set the properties StartFrame and EndFrame, as well as Repeats. After that, you must set Playing to True. To stop playing, you can set Playing to false again. If the animation should be played automatically when the form is activated, you can set AutoPlay to true. If the animation ought to be centered in the component, you can set Center to true, otherwise the size of the component will be adjusted to the size of the animation.

One of the colors in the animation is defined as a transparent color. If you want to play the animation, using all original colors, you should set Transparent to False.

Note: Although TAnimation was made for Delphi 2 and was made more or less obsolete by the TAnimate component of Delphi 3, it will still work in higher versions of Delphi.

Properties

Additionally to the properties all VCL components have, TAnimation has the following new or overridden properties:

Animation property

Contains the file or resource name of the animation.

property Animation: string;

This property is the name of the file which contains the animation. This must be a silent .avi file, other .avi files do not work. Alternatively, you can place here the name of a resource you have either included in your program, or one of the built-in resources.

AutoPlay property

Enables automatic playing.

property AutoPlay: Boolean default False;

If you want the animation to start immediateley after the form was created, you can set this property to True.

Center property

Enables centering the animation.

property Center default True;

Normally, the component will adjust it’s size to the size of the animation. You can make the component center the animation, so the component can be larger than the animation is. To make the component center the animation, set Center to True.

EndFrame property

Contains the last frame to be displayed.

property EndFrame: Integer;

Endframe is the last frame of the animation, that will be displayed. So if you only want to show part of the animation, you can set both StartFrame and EndFrame to the frame numbers you like. The default value is -1, which means that the end frame is the last frame in the animation.

Frame property

Contains the number of the standard frame.

property Frame: Integer default 0;

With this property you can determine which frame will be displayed, when the animation is not being animated (if Playing is false). The default is 0, which is the first frame in the animation.

Playing property

Starts the playing of the animation.

property Playing: Boolean;

With this property, you can make the animation play the frames set by StartFrame and EndFrame. If Playing is False, the frame with the number in property Frame will be displayed. If Playing is True, the animation will go from StartFrame to EndFrame. If Repeats is not 0, the animation will be played Repeats times. If Repeats is -1, the animation will repeat as long as Playing is True.

Repeats property

Contains the number of times the animation is repeated.

property Repeats: Integer default -1;

With this property you can select, how many times the animation will be repeated. Normally, with the default value of -1, the animation will repeat as long as Playing is True. If you set Repeats to a value higher than 0, the animation will only be repeated that many times.

Resource property

Contains the standard resource type.

property Resource: TAVIResource default arNone;

To make the selection easier for you, the standard Windows animations were already built into the component. Property Resource is of type TAVIResource. You can select one of the animations in the Object Inspector, or by specifying one of the values of AVIResource.

type
  TAVIResource = (
    arNone, arCopyFile, arCopyFiles, arDeleteFile,
    arEmptyBin, arEmptyFolder, arSearchFile,
    arSearchFolder, arSearchHardware, arUser);

TAVIResource can have the following values:

Value Description
arNone no animation
arCopyFile as displayed when copying one file in the Explorer
arMoveFile as displayed when copying multiple files in the Explorer
arDeleteFile as displayed when deleting a file to the paper bin
arEmptyBin as displayed when emptying the paper bin
arEmptyFolder as displayed when deleting a folder
arSearchFile as displayed in the Search for Files dialog in the Explorer
arSearchFolder as displayed when searching for a link target in the Explorer
arSearchHardware as displayed in the dialog for hardware
arUser user defined animation

StartFrame property

Contains the first frame to be played.

property StartFrame: Integer default 0;

StartFrame is the frame, at which the animation will start playing.

Transparent property

Enables or disables transparency.

property Transparent: Boolean default True;

Normally, one of the colors of the animation is considered to be transparent,usually the background color. Any part of the animation which has this color, will display the underlying structure. If you set Transparent to False however, the real color of will be displayed, covering the background structures.

Custom AVI Resources

You can create your own resources for TAnimation, using either the Borland Resource Workshop version 4.5 or up (if you can find it somewhere), or using the supplied command line resource compiler (in the bin directory of your Delphi installation). Here the method using the command line resource compiler is described.

First, create a .rc, a resource source file. In this, you enter a custom resource of type AVI. So if you want to include an AVI which is in file “MoveFile.avi” and you want to call it MoveAVI, you’ll have to create a file, let’s call it “MyAVI.rc” and include a line like this:

MoveAVI AVI     "movefile.avi"

Now you can compile this file into a .res file with a resource compiler like BRCC32 and include it in your project with {$R MyAVI.res}. In newer versions of Delphi, you only have to add your .rc file to the project, and the IDE will take care of everything else.

Instead of the above, you can use Colin Wilson’s XN Resource Editor or Anders Melander’s Resource Editor which are both optimized to work with Delphi (and are both written in Delphi too).

Newer Delphi or RAD Studio versions have a built-in resource capability which lets you add resources to a project using the IDE: More about that on the DocWiki.

Standard Disclaimer for External Links

These links are being provided as a convenience and for informational purposes only; they do not constitute an endorsement or an approval of any of the products, services or opinions of the corporation or organization or individual. I bear no responsibility for the accuracy, legality or content of the external site or for that of subsequent links. Contact the external site for answers to questions regarding its content.

Disclaimer and Copyright

The coding examples presented here are for illustration purposes only. The author takes no responsibility for end-user use. All content herein is copyrighted by Rudy Velthuis, and may not be reproduced in any form without the author's permission. Source code written by Rudy Velthuis presented as download is subject to the license in the files.

Valid HTML5! Valid CSS!