Search code examples
delphiurluriopenfiledialog

Delphi: OpenFileDialog crashes with URL


Giving a URL to the TOpenFileDialog, the Execute method throws an exception:

OpenDialog1.Filename := 'http://www.osfi-bsif.gc.ca/app/DocRepository/1/eng/issues/terrorism/indstld_e.xls';
bResult := OpenDialog1.Execute;

But you are allowed to open files from a URL.

Delphi 5


Solution

  • TOpenDialog is just a wrapper for the windows function GetOpenFileName in comdlg32.dll.

    function TOpenDialog.Execute(ParentWnd: HWND): Boolean;
    begin
      Result := DoExecute(@GetOpenFileName, ParentWnd);
    end;
    

    Unfortunately the documentation for this function isn't that great. But I'm pretty sure it doesn't support http.