I’m using a TOpenPictureDialog to browse for images. In debug mode, when I’m browsing in this dialog for a picture and I happen to click (not double click) on a shortcut (.lnk), the debugger interrupts my program because it catches an exception, saying it’s not a valid file format.
How to overcome this? I know it’s only in debug time and don’t have any issue in the final EXE, but it is getting very annoying, because I’d like to be able to go through these shortcuts.
You are out of luck here, this bug was reported in the QC 69533 and was fixed in the update 3 of Delphi 2009.
The code used to by the VCL to verify if a file is valid image, doesn’t check for the shortcuts files (.lnk) so the VCL thinks which the file is a valid image and try to load the file and then raises a EInvalidGraphic exception.
The exception is only raised in the debugger because a code like this is used to check the validate the filename.
(Only showing part of the real code because is VCL code)
Workarounds
1) You can add the EInvalidGraphic exception, to the
exceptions list to ignorelist.2) you can write a detour (here you have a sample) and implement your own
TOpenPictureDialog.DoSelectionChangemethod (validating the.lnkfiles), because is here where is made the validation of the files to load.3) you can override the
DoSelectionChangemethod of theTOpenPictureDialogusing a interposer class, to validate the files to load.