TSaveDialog and 2 formats with same extension

172 views Asked by At

In TSaveDialog I added 2 formats with the same extension:

Format A|*.form
Format B|*.form
Format C|*.diff

Now I want to identify which format user chose:

var Ext: String;
begin
  if not SaveDialog1.Execute then Exit;

  Ext := LowerCase(ExtractFileExt(SaveDialog1.FileName));

This way I can differentiate "Format B" from "Format C" but I can't "Format A" from "Format B".

2

There are 2 answers

3
David Heffernan On BEST ANSWER

Use the FilterIndex property to identify which filter was selected when the dialog was actioned.

0
Jerry Dodge On

While David's answer directly relates to the question as it's asked, there's more to consider when determining user intentions. You can't necessarily rely on just the file extension to know what the user wants to do. After all, the user could manually type .form into the filename themselves, and then what should you do?

Instead, such options shouldn't be implemented on this level. In my experience, such things are implemented on an intermediate level. For example, think of video editing / production. The user may wish to render the video as an MP4 video. Or perhaps an AVI. However, each of those possible formats has a wide variety of other specific options, such as video codecs, quality, and more.

What needs to be done in situations like this is to provide an additional layer of user options before saving a file. Let it be part of a "project" in a sense. User does what they need to do with their content, and part of the process is deciding what type of output format they intend to produce. When the user decides to save, before prompting them for the filename, first prompt them for other specific format options, depending on what formats your application supports.

Long story short, don't rely on the file extension itself to identify all of the user's intentions. There should be an intermediate level of user choice how the file should be formatted, before choosing the output extension.