How Delphi files are packaged (compiling multiple files into a single unit)

Source: Internet
Author: User

Delphi File Packaging MethodIn a Delphi project, there is usually one that is the same as the project name Master name. Res file, which is used to save the application icon and other resources, corresponding to this file, in the project file must contain the compilation instructions "{$R *.res}", telling the compiler to compile with the same name as the project master. Res file. Similarly, if you need to include all file types in your application as resources, you can also take advantage of them. Res file. This article will show you how to use the Res file to include files inside the Delphi program.

One created. Res file

Here is an example of a set of audio files. First write the file "Mymusic.rc" with all text editors such as Notepad. The format and contents of the file are as follows:

SRC1 FILE1 Onlyyou.mp3
SRC2 FILE2 Yesterdayoncemore.mp3
SRC3 FILE3 Moonriver.mp3

where each row represents a resource declaration, each resource declaration contains three parameter definitions, the first parameter is the name of the resource, the second parameter is the type description of the resource (this example defines three classes), and the third parameter is the file name. Parameters must be separated by a space.

After writing the completed "mymusic.rc" file, put it and the above three. The MP3 file is placed in the same directory (to avoid the hassle of setting the path). Then run the application Brcc32.exe at the following command line (located at: \delphi6\bin): Brcc32 mymusic.rc It is important to note that the command can only be executed in the command line mode. If the system's PATH environment variable does not include the Delphi run path, then you will also need to Brcc32.exe and mymusic.rc, three. The MP3 file is placed in the same path. Run the above command line, will be in the same path to get the file "Mymusic.res", which is a separate complete resource file, the format is to follow the Windows system standards, so can be used in a variety of research and development environments such as VB, VC, Cbuilder and so on.

Two declarations contained in the program. Res file

You just need to be in a cell in the project (the best is the unit you need to take advantage of these resources, which will make your application more readable) add the following compilation instructions: $R mymusic.res}{

Although the compilation instruction can be located at all locations of the cell, it is best to tie it to the compilation indicator "{$R *.DFM}" (each containing the form file) in order to make your original code structure reasonable. The compiler instructions here explicitly tell the compiler that the resource file "Mymusic.res" needs to be included in the application when compiling the application.

Three get resources at run time

The above two-step work is only the basis (but must be necessary), the use of resources is the fundamental purpose. The following procedure will show you how to restore the resources (files) contained in your application.

Procedure Musicrestofile (const resname, restype,filename:string); Varres:tresourcestream;beginres: = Tresourcestream.create (Hinstance,resname, PChar (restype)); Res.savetofile (FileName); Save the resource as a file, that is, restore the file//You can also do other flow operations, in memory to achieve the use of resources without saving as a file res.free;end;

Examples of calls to this procedure are: musicrestofile (' SRC2 ', ' FILE2 ', ' Thesecondmusic.mp3 ');

It is worth mentioning that, using this method, you finish the Magnum production of its own installation program, the installer contains only one executable file, in the executable file as a resource to include all the content to be installed (file). In addition, if you need to play external audio files (such as background music, sound cues, and so on) in your application, you can also include these external files in your application, thus preventing users from mistakenly deleting the audio files and causing the application to be incomplete.

How Delphi files are packaged (compiling multiple files into a single unit)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.