1. Write RC script text
Write an extension called ".rc" with a notebook or other text editor. The format is as follows:
Resource Identifier Resource Type Keyword Resource File Name
Where "Resource Type Keyword" is used to identify the type of resource file:
AVI silent animation
Bitmap bitmap file
Cursor cursor file
Icon icon file
Wave sound file
All listed above are standard resource types, or you can customize a type, such as "MyType". However, both are somewhat different in the call mode (in detail in the following example "Bitchart in the resource file).
2. Compile to RES resource files based on the RC script file
Enter the following in the command prompt:
Brcc32 filename.r // Note: brcc32.exe in the delphix / bin directory
3. Add a resource file in the Delphi unit
Copy the generated RES resource file to the directory where the corresponding program is located, add "{$ r * DFM}" in the unit file, add "{$ r filename.res}", and the resource file is included in the compiled resource file. Execute the file.
Description: If you are in two step two steps, you can use a simpler practice, ie, add the RC file directly to the project, which will automatically compile the resource file when compiling the Delphi project.
4. Example of resource file call
(1) Bitmap in the access resource file
// rc: TestBmp Bitmap Res / Test.BMP
Image1.Picture.bitmap.LoadFromResourceName (Hinstance, 'RES / TEST.BMP');
// rc: TestBmp BMPTYPE RES / TEST.BMP
VAR
RESSTREAM: TRESOURCESTREAM;
Begin
RESSTREAM: = TRESOURSOURESTREAM.CREATE (Hinstance, 'TestBmp', 'BMPTYPE');
Image1.Picture.bitmap.LoadFromstream (RESSTREAM);
RESSTREAM.FREE;
END;
Please pay attention to the differences between the two calls above.
(2) Access icons in resource files
Place the icon in the resource file and dynamically change the icon of the application.
// RC: Testicon icon res / test.ico
Application.icon.Handle: = loading, Hinstance, 'Testicon';
(3) Access AVI animation in resource files
// RC: Testavi avi res / test.avi
Animate1.Resname: = 'Testavi';
Animate1.Active: = true;
(4) Access JPEG images in resource files
In order to process the JPEG image, the JPEG unit must be referenced at the interface.
VAR
JPG: TJPEGIMAGE;
RESSTREAM: TRESOURCESTREAM;
Begin
JPG: = tjpegimage.create;
RESSTREAM: = TRESOURSOURESTREAM.CREATE (Hinstance, 'Testjpg', 'JPGTYPE');
Jpg.LoadFromstream (RESSTREAM);
Image1.Picture.Assign (JPG);
Jpg.free;
RESSTREAM.FREE;
END;