Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

Example #4: Listing specific resources from a file

We can use the IsMatching method of TPJResourceEntry to check if a specific resource matches some given criteria. IsMatching can match just a resource type, a resource type and name or it can uniquely identify a resource in a file by matching its type, name and language id.

Like TPJResourceFile.FindEntry, the language id parameter is optional. The resource name parameter can be nil if we don’t want to specify the resource name in the match.

Using IsMatching, we can list all the RT_HTML resources from a resource file in a TMemo control with this code:

var
  ResFile: TPJResourceFile;
  Entry: TPJResourceEntry;
  Idx: Integer;
begin
  ...
  // Assume ResFile contains a loaded resource file
  ...
  for Idx := 0 to Pred(ResFile.EntryCount) do
  begin
    Entry := ResFile.Entries[Idx];
    if Entry.IsMatching(RT_HTML, nil) then
      Memo1.Lines.Add(
        Format('%s', [ResIDToStr(Entry.ResName)])
      );
  end;
  ...
end;

To list just the different language versions of the RT_HTML resource named 'INDEX_HTML' we simply change the IsMatching method call in the for loop to:

Entry.IsMatching(RT_HTML, 'INDEX_HTML')

Finally, to list all the RT_HTML resources with language id $0809, regardless of name, we can pass nil as the ResName parameter and specify the language id as the final parameter. With these changes the IsMatching method call becomes:

Entry.IsMatching(RT_HTML, nil, $0809)

Links: