Resource file (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Delphi Compiler Directives (List) Index

Type

Parameter

Syntax

{$R <resfile> <predicates>} {$RESOURCE <resfile> <predicates>}

Scope

Local


Remarks

The $R directive specifies the name of a resource file to be included in an application or library. The named file must be a Windows resource file, and the default extension for filenames is .res. To specify a file name that includes a space, surround the file name with single quotation marks: {$R 'My file'}.

The * symbol has a special meaning in $R directives: it represents the base name (without extension) of the source code file where the directive occurs. Usually, an application's resource (.res) file has the same name as its project (.dpr) file; in this case, including {$R *.res} in the project file links the corresponding resource file to the application. Similarly, a form (.dfm or nfm) file usually has the same name as its unit (.pas) file; including {$R *.nfm} in the .pas file links the corresponding form file to the application.

The {$R filename.res filename.rc} (where the two occurrences of 'filename' match) makes the .rc file appear in the Project Manager. When the user opens the .rc file from the Project Manager, the String Table editor is invoked.

When a {$R filename} directive is used in a unit, the specified file name is simply recorded in the resulting unit file. No checks are made at that point to ensure the filename is correct and points to an existing file.

<predicates> is an optional parameter that consists of a list of identifiers separated by spaces or tabs.

If at least one symbol is defined, the {$R <resfile>} directive is processed. If the defined symbol does not exist, this directive is ignored.

When an application or library is linked (after compiling the program or library source file), the resource files specified in all used units, as well as in the program or library itself, are processed, and each resource in each resource file is copied to the executable being produced. During the resource processing phase, the linker searches for .res files in the same directory as the module containing the $R directive, and in the directories specified in the Search path input box on the Directories/Conditionals page of the Project > Options dialog box.