Example #7: Checking if a resource exists

If you attempt to add a duplicate of an existing resource to a resource file an exception will be raised. To avoid this we may need to check if a resource already exists. This can be done with the EntryExists method of TPJResourceFile as follows:

var
  ResFile: TPJResourceFile;
  Entry: TPJResourceEntry;
begin
  ...
  // Assume ResFile references a valid object
  ...
  if not ResFile.EntryExists(RT_RCDATA, 'FORTYTWO', $0809) then
    Entry := ResFile.AddEntry(RT_RCDATA, 'FORTYTWO', $0809);
  ...
end;

EntryExists can also be used to perform partial checks for entries. It can omit the name and / or the language id when searching for resources. You can take advantage of this behaviour to get some useful information about the resource file. Examples are:

Links: