Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8063937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:12:37+00:00 2026-06-05T11:12:37+00:00

I am building a TFileSaveDialog descendent component. The descendent has a PushButton who’s event

  • 0

I am building a TFileSaveDialog descendent component. The descendent has a PushButton who’s event is handled by:

function TFileDialogEvent.OnButtonClicked(const pfdc: IFileDialogCustomize;
  dwIDCtl: DWORD): HResult; stdcall;
var
  iImageEnIO: TImageEnIO;
  iFilename: string;
  iName: PChar;
  pfd: IFileDialog;
begin
  if dwIDCtl = dwVisualGroup8ID then
  begin
    iImageEnIO := TImageEnIO.Create(nil);
    try
      FileDialog.QueryInterface(
    StringToGUID('{8016B7B3-3D49-4504-A0AA-2A37494E606F}'),
    pfd);
    // How to get correct valid handle to IFileDialog?
      pfd.GetFileName(iName);
      iFilename := string(iName);
      if FileExists(iFilename) then
      begin

The component also displays image information in various control labels correctly. The component sucessfully returns the selected filename and allows changing folders, but the getting the filename from pfd.GetFileName(iName) in the OnButtonClicked event is returning an invalid filename. I think the problem is caused by not getting the correct handle for pfd: IFileDialog.

UPDATE:
I solved this by defining
FileDialog: IFileDialog as a var at the component level then I called

function TFileDialogEvent.OnButtonClicked(const pfdc: IFileDialogCustomize;
  dwIDCtl: DWORD): HResult; stdcall;
var
  iImageEnIO: TImageEnIO;
  iFilename: string;
  pFolder: PWideChar;
  iFolder: string;
  iName: PChar;
  pfd: IFileDialog;
  hr: HRESULT;
  aShellItem: IShellItem;
begin
  if dwIDCtl = dwVisualGroup8ID then
  begin
    iImageEnIO := TImageEnIO.Create(nil);
    try
      FileDialog.QueryInterface(IFileDialog, pfd);
      pfd.GetFileName(iName);
      // Get the ShellItem
      hr := SHCreateItemFromParsingName(iName, nil,
      StringToGUID(SID_IShellItem), aShellItem);
      // Get the folder
      pfd.GetFolder(aShellItem);
      // Get the folder displayname
      aShellItem.GetDisplayName(SIGDN_FILESYSPATH, pFolder);
      iFolder := string(pFolder);
      if DirectoryExists( iFolder) then
        iFilename := IncludeTrailingPathDelimiter( iFolder) + string(iName);
      if FileExists(iFilename) then
      begin

Thank-you all… Thank-you Rob… your post was helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:12:38+00:00Added an answer on June 5, 2026 at 11:12 am

    You’re querying the object for an interface matching the GUID {8016B7B3-3D49-4504-A0AA-2A37494E606F}, and storing the result in an IFileDialog reference. The problem is that {8016B7B3-3D49-4504-A0AA-2A37494E606F} is the GUID for the IFileDialogCustomize interface, not IFileDialog. You attempt to call GetFileName, which is the sixth method of the IFileDialog interface, but since the variable actually holds an IFileDialogCustomize interface, control ends up being transferred to the sixth function of that interface instead. The compiler cannot catch the type mismatch for you, partly because you’re constructing the GUID dynamically at run time (so it doesn’t know the value at compile time), and partly because the second parameter to QueryInterface is untyped (so it can’t know that the type of the variable is supposed to match the first parameter).

    There’s an easier way than computing the GUID at run time. Interface types are automatically useable as their associated GUIDs (when they have GUIDs). To request the IFileDialog interface, just pass that identifier directly to QueryInterface:

    FileDialog.QueryInterface(IFileDialog, pfd);
    

    You don’t even have to call QueryInterface if you use the as operator:

    pfd := FileDialog as IFileDialog;
    

    When you call QueryInterface directly, you need to make sure you check the result for error codes. If you use the as operator, an unsupported interface will raise an exception. If you just want pass-fail without too much error checking, use the Supports function instead:

    if Supports(FileDialog, IFileDialog, pfd) then ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Building a website that has English & Japanese speaking users, with the Japanese users
When building a Delphi 2009 component package, how do you specify which directory should
building a site which has content for each section. urls range from; /work/ /work/print/
building upon the $.fn.serializeObject() function from this question , i'd like to be able
Building on what has been written in SO question Best Singleton Implementation In Java
Building an app using a calendar on a Google Apps domain that has SSL
Building an inventory system. I have lots of products and each product has three
Building a new Mobile Web Platform for Mobile Users to purchase & download content
building a site using PHP and MySQL that needs to store a lot of
Building a Django app on a VPS. I am not very experienced with setting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.