Forum > Win32/64

Issue with Win32 TSaveDialog.DefaultExt

<< < (6/7) > >>

wp:
OMG - I think I will not be able to remember this...

I wrote a small test project - maybe you have similar one - which varies the parameters for the TOpenDialog and the TSaveDialog interactively and displays the generated filename. I compiled it with Laz/main, Laz 2.2.6 and with Delphi XE11.3 Community Edition (the application compiles with Delphi 7 as well, however, delivers different results).

I did not check all of the parameter combinations (there might be thousands of them...). Here is just an excerpt of my (incomplete) analysis file(included in the attached zip)  comparing the case "DefaultExt=pas; FilterIndex for "all files" with mask "*.*", with/without option ExtensionDifferent" for the SaveDialog:


--- Code: -----------------------------------------------------------------------------------
DEFAULT EXTENSION 'pas', all files (*.*)
--------------------------------------------------------------------------------
TSaveDialog; all files mask='*.*'; DefaultExt='pas'; FilterIndex=1; ExtensionDifferent = False

                                    Laz/main        Laz 2.2.6       Delphi
                                    ------------    -------------   ------------
  Test #1: FileName=test       -->  'test.pas'      'test.pas'      'test.pas'
  Test #2: FileName=test.pas   -->  'test.pas'      'test.pas'      'test.pas'
  Test #3: FileName=test.pp    -->  'test.pp.pas'   'test.pp'       'test.pp'
  Test #4: FileName=test.yml   -->  'test.yml.pas'  'test.yml'      'test.yml'
  Test #5: FileName=test.abc   -->  'test.abc.pas'  'test.abc'      'test.abc'
 
TSaveDialog; all files mask='*.*'; DefaultExt='pas'; FilterIndex=1; ExtensionDifferent = True

                                    Laz/main        Laz 2.2.6       Delphi
                                    ------------    -------------   ------------
  Test #1: FileName=test       -->  'test.pas'      'test.pas'      'test.pas'   
  Test #2: FileName=test.pas   -->  'test.pas'      'test.pas'      'test.pas'   
  Test #3: FileName=test.pp    -->  'test.pp'       'test.pp.pas'   'test.pp.pas'
  Test #4: FileName=test.yml   -->  'test.yml'      'test.yml.pas'  'test.yml.pas'
  Test #5: FileName=test.abc   -->  'test.abc'      'test.abc.pas'  'test.abc.pas'
--- End code ---
As you can see, the result for Laz 2.2.6 and Delphi are in agreement. But the current main version gets the same results only when the ExtensionDifferent is flipped - well, exactly what you did.

But since Laz/main breaks here compatibility with prior versions and with Delphi, I think this change should be reverted.

Bart:

--- Quote from: wp on August 21, 2023, 12:21:19 am ---But since Laz/main breaks here compatibility with prior versions and with Delphi, I think this change should be reverted.

--- End quote ---

I strongly disagree.

Read the documentation of MS on FOS_STRICTFILETYPES: "In the Save dialog, only allow the user to choose a file that has one of the file name extensions specified through IFileDialog::SetFileTypes."
So, this option restricts extensions to be only one of the extensions in the Filter or DfeaultExt property. It restricts the user form typing a filename that he/she wants.

Delphi says about ofExtensionDifferent: This flag is turned on at runtime whenever the selected filename has an extension that differs from DefaultExt. If you use this flag in an application, remember to reset it.
This is not what the MS Docs say IMO, nor is it how it behaved in the past IIRC. (I would have to check with Delphi 7.)
(The FOS_STRICTFILETYPES flag is new to the Vista dialogs though, it did not exist before. Pre-Vista this flag was mapped to the OFN_EXTENSIONDIFFERENT flag of the LPOPENFILENAME struct.)

Our help says: Allows a file name with an extension which does not match the filters or default extension in a file dialog. (which is the opposite of what FOS_STRICTFILETYPES does)

AFAIK the FOS_STRICTFILETYPES is not set by Windows as a reaction to what the user types.

Does Delphi really behave as the dosc say? In your example: with ofExtensionDifferent turned off, type test.abc (which will retunr test.abc as filename in your example): is ofExtensionDifferent now set in Options?
And how about this then: "If you use this flag in an application, remember to reset it.", if it really works as they say (select a different extension and the flag will be set), why do you not have te reset this then the next time you execute the dialog. Why only if you ever set it at designtime? It makes absolutely no sense to me at all.

Bart

Bart:
Just noticed that Delphi uses TFileDialogOption for their Vcl.Dialogs.TCustomFileDialog, which is their abstarct base class for " Vista or later Windows operating systems style file dialogs".

"fdoStrictFileTypes: The file extension of a saved file being must match the selected file type."

Conclusion 1 of all this: there is no 1-on-1 translation between TOpenOption.ofExtensionDifferent and any of the Vista flags.
Conclusion 2: applying FOS_STRICTFILETYPES if ofExtensionDifferent is set, makes no sense whatsoever.

We'll either have to live with it, or also implement TFileDialogOption.

Life sucks ...

Bart

TRon:

--- Quote from: Bart on August 21, 2023, 03:30:04 pm ---Life sucks ...

--- End quote ---
That should read:

--- Quote ---Life sucks ... when using windows.

--- End quote ---

There /is/ a simple solution ... :P  ;)

Bart:

--- Quote from: TRon on August 21, 2023, 06:52:13 pm ---
--- Quote ---Life sucks ... when using windows.

--- End quote ---

There /is/ a simple solution ... :P  ;)

--- End quote ---

Not really, since we have to support Windows and be as Delphi compatible as possible (without implementing their bugs as well)  ;D

Bart

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version