Embed a file in the exe file and release

xiaoxiao2021-03-05  28

There have been many articles in previous problems, but the methods described in these old articles usually make more jobs, but do not need to work because of a simpler method in Delphi5.

First, I want to introduce you to a demo program that comes with Delphi5. This program is "Resource Explorer", you can find the function of this program in the "Delphi5 '" directory, maybe you have guess it, it is a browsing resource (resource).

This is a compact and convenient tool that proceeds, it can separate any resource files from a DLL or execution file, using it you will be surprised to find that it contains so much resources in WINWORD.EXE. Here, we use this tool just to confirm that we have added resource files to our test file.

Using Delphi5, increasing resources or releases resources from the EXE file, you can do it as follows:

1. Start a new application engineering (select menu file | new application), then add a file file to the project (File | New ... -> text). This text file will contain all your resources, the format is "Resource Name Resource Type File Name", such as "PDF RCDATA foo.pdf", where rcdata means this is an arbitrary binary. If you want to join more resources, add more rows. In this step, it is necessary to do a job is to save the project. It should be noted here that the Delphi editor will automatically add ".txt" extension to your text file, and we need ".rc" extension. You can force Delphi to save files with ".rc" extension, just need to add double quotes to file names, such as "MyResources.rc".

2. Compile your project file to confirm that your resource has been added to the execution file. Run "Resource Explorer", open your execution file, and check if your resource is added to "RCDATA".

3. Now, you will now release your resource file from the execution file. The programmers of Borland have written corresponding code, which makes you use very easy. All code has been encapsulated in TResourceStream, what you need to do is the following work:

Procedure TForm1.Button1Click (Sender: Tobject); Var rs: TresourceStream; Begin Rs: = TRESOURSTREAM.CREATE (0, 'PDF', RT_RCDATA); TRY RS.SAVETOFILE ('bar.pdf'); Finally Rs.Free; end ;

TResourceStream.create creates a resource stream, which contains resources in the current process "0" name "PDF", which is predefined as a constant type "RT_RCData".

转载请注明原文地址:https://www.9cbs.com/read-36032.html

New Post(0)