Back


Inserting an AVI file into your .exe


This is helpful if you do not want to have an AVI file in the directory of the program you distribute.
One problem with inserting an AVI file into your .exe is that it makes your programs .exe larger,
so it is a good idea if your program uses small AVI files or maybe one or two large AVI files.
The Delphi example below should work on any version of Delphi above Delphi 2.

First open an editor like Notepad.exe, for this example we will use an AVI file called bbb.jpg
and this is the AVI file we will insert into our programs .exe
(Make sure that there is an AVI in your folder/directory named bbb.avi. If you do not have an AVI
already called bbb.avi you can rename a different AVI file so that it is called bbb.avi)

Type these words into the text file:

TheAnimation AVI "bbb.avi"

Then save the text file as:

MyAvi.rc

We will use BRCC32.exe that comes with Delphi, it should be in Delphi's Bin directory, to compile the file.
In order to use BRCC32.exe you have to use a DOS window, using DOS is not hard at all.
To run a DOS window, go to your TaskBar, click Start|Programs|MS-DOS Prompt
Whenever you use DOS all you have to do to get back to Windows (Your desktop) is type the word Exit, then
press the Enter key.

You should have your AVI file and your .rc file in the same folder/directory.

So we will type this sentence in the DOS window:
C:\Delphi 3\Bin\Brcc32.exe C:\Delphi 3\bin\avi\MyAvi.rc
The above paths may have to be changed to the place where you have Delphi installed and to the
folder/directory where you have saved your files for this example.

If this does not work or you get an error, you may not have Delphi in your computers path.
A way around this is for you to copy the BRCC32.exe and RW32CORE.DLL into your folder/directory that
you are using, then try again.
(The above files, BRCC32.exe and RW32CORE.DLL, may be different for different versions of  Delphi)

Use Explorer or another File Manager and have a look in your directory, you should find that you have an extra file called MyAvi.RES.

Start Delphi, then start a new project (Application).

Look for {$R *.DFM} in Unit1 and add {$R MYAVI.RES} next to it.

Add a TAnimate component to your form and make sure its AutoSize property is set to True.
Next drop a Button onto your Form, double-click on the Button and add this code:

Animate1.ResName := 'TheAnimation';
Animate1.ResHandle := 0;
Animate1.Active := True;

Note we use 'TheAnimation' to call the AVI file.
Run the program and then click on the Button, you should see the AVI that you put into the resource file.
If you have to save the project before you can run it, save in in the same folder/directory where you have the resource (*.RES) file.


Your complete unit should look like this:
 

unit Unit1;
interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Animate1: TAnimate;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM} {$R MYAVI.RES}

procedure TForm1.Button1Click(Sender: TObject);
begin
   Animate1.ResName := 'TheAnimation';
   Animate1.ResHandle := 0;
   Animate1.Active := True;
end;

end.


Back