Open file dialog filter by file contents

I typically use TOpenDialog with its Filter property for narrowing down available files for the user. I would like to further filter these files down by their content.

For example, the open file dialog should display only files with a ".bin" filename extension and its first 4 magic bytes are 0x7F, 0x45, 0x4C, 0x46 (ELF executable).

The condition will not always necessarily be identifying certain executable formats, but other binary data as well.

Is there a standard way of doing this in Delphi/VCL or do I have to postpone the content inspection until after the user has selected the file?


There's no way to achieve what you want. The system file dialog does not allow you to filter the files that it displays based on their content.

The OnIncludeItem event tantalisingly appears to do what you need. However, it has the following problems.

  1. The event wraps the CDN_INCLUDEITEM notification. This notification is fired by the legacy XP common dialog boxes, but not by the modern common item dialog. So, using the event forces the legacy XP common dialog boxes onto your program. If for no other reason, this has cosmetic downsides.
  2. More significantly, handling CDN_INCLUDEITEM has no impact on files. It only influences non-filesystem shell objects. Form the documentation:

The dialog box always includes items that have both the SFGAO_FILESYSTEM and SFGAO_FILESYSANCESTOR attributes, regardless of the value returned by CDN_INCLUDEITEM.

Related questions:

Need Your Help

SDL_LoadBMP loads the bitmap upside down and mirrored

opengl sdl textures

SDL_LoadBMP loads the bitmap upside down and mirrored in OpenGL. What may be the problem ?

popup dialog box background 100% height

jquery css

I am working on a onClick dialog popup window functionality. I have popup window of 200 x 200 px. onClick of the button the box is get opened & now I want that the content behind the box should...