简体   繁体   中英

Delphi adding and using multiple resource files *.RES inside exe/dll

I have question regarding using *.RES files in delphi.

eg I have two resource files: 1.RES and 2.RES. Both of these RES files contains different image called IMAGE1 (jpg).

I add RES files to Delphi application using these commands:

{$R '1.RES'}
{$R '2.RES'}

How can I specify which resource file to use? I use these commands when I want to retrieve image if I have only one RES file:

var RS : TResourceStream;
    jpg : TjpegImage;

RS := TResourceStream.Create(HInstance,'IMAGE1',RT_RCDATA);
jpg.LoadFromStream(RS);

Now, how can I know what will it load if I have 2 RES files? I think I need to control HInstance but I just cannot grasp how.

The names of resources within a given module must be unique, just in the same way as variables in a function must have unique names, files in a directory must have unique names and so on. So, if you put two resources with the same name into the same module, one resource will get discarded and you will only be able to retrieve the remaining resource.

In case you are unclear on what a module is, I'll try to explain. A module is a DLL or an executable, or a Delphi package. Your executable file is a single module, with a single instance handle. It is linked to DLLs, each of which are separate distinct modules. Any packages that your executable load are also distinct modules. You can have resources in those other modules that have the same name as resource in your executable.

I think I need to control HInstance but I just cannot grasp how.

That cannot help as I hope you now understand. The value HInstance identifies the module and in your code it refers to the module associated with the executable.

Your options:

  1. Give the resources different names.
  2. Put the resources into different modules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM