System.LoadResource is a function in the Delphi RTL (Run-Time Library) that allows you to load a resource from an executable file or a module. Resources are data that are stored in a binary format and can be accessed by an application at runtime. Examples of resources include strings, images, and sounds.
To use System.LoadResource, you will need to include the System unit in your program and call the LoadResource function, passing it the handle of the module that contains the resource and the resource identifier.
Here’s an example of how to use LoadResource to load a string resource
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
uses System.SysUtils, System.Classes, System.Types, System.UITypes; function LoadStringResource(Module: HMODULE; ResourceID: Integer) string; var ResStream: TResourceStream; begin ResStream := TResourceStream.CreateFromID(Module, ResourceID, RT_RCDATA); try Result := ResStream.DataString; finally ResStream.Free; end; end; var S: string; begin S := LoadStringResource(HInstance, 1); ShowMessage(S); end; |
In this example, HInstance is a predefined global variable that holds the handle of the current module (i.e., the executable file or DLL that contains the code). The resource identifier is an integer value that identifies the resource within the module.
You can also use LoadResource to load other types of resources, such as images or sounds. The Delphi documentation includes more information about working with resources in Delphi.
Leave a Reply