Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TSaveDialog and 2 formats with same extension

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".

like image 852
Tom Avatar asked Oct 28 '19 17:10

Tom


2 Answers

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

like image 107
David Heffernan Avatar answered Nov 10 '22 12:11

David Heffernan


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.

like image 27
Jerry Dodge Avatar answered Nov 10 '22 14:11

Jerry Dodge