Correct posture to call TBrowseForFolder

[Tutorial] Correct posture for calling TBrowseForFolder

TBrowseForFolder is a directory browsing dialog box that comes with Delphi / C++ Builder. It is located in the StdActns unit (the latter is the Vcl.StdActns unit). Unfortunately, this action code is born disabled (the problem has not been changed since its birth), To make it work, there are two solutions:

The first type: scraping the bone to cure poison => modify the code of the StdActns unit

  1. Copy the StdActns unit to your project directory;
  2. Open the cell and in the TBrowseForFolder.ExecuteTarget implementation, find the following code:

    Change the value of hwndOwner from Application.Handle to:

    Then compile the unit using Release/Debug mode respectively.
  3. Copy the dcu of the corresponding StdActns in the two modes of Release/Debug to the corresponding location in the installation directory of Delphi/C++ Builder, overwriting the original dcu file.

The second: Opportunity => Since the hwndOwner you set is Application.Handle, I should put the Application.Handle window in front before calling this action, so that the pop-up browse directory dialog box will not run behind another window. Therefore, the correct posture at this time becomes:

Note that at this point, you can't bind the action to a control, but call it manually in an event like the control's OnClick.

Well, compare the pros and cons of the two:

  • The only problem of the first type is that you need to deal with it every time you upgrade Delphi until the official revision of this problem;
  • The only problem with the second is that you have to write two more lines of code, and you don't need to worry about the Delphi upgrade.

How to choose is up to you, not me. The same problem, still exists in FMX, the same way to solve.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325078826&siteId=291194637