Save dialogs and default file extension

no help is with any save dialogs of how to set them up
how do I get a default extension installed on all of them before opening

https://www.delphibasics.co.uk/RTL.php?Name=TSaveDialog#:~:text=Delphi%20Basics%20%3A%20TSaveDialog%20command&text=The%20TSaveDialog%20is%20a%20visual,by%20defining%20a%20TSaveDialog%20variable.

Just in case thereā€™s a problem with the OPā€™s help install, bookmark this link

https://docwiki.embarcadero.com/RADStudio/Athens/en/Main_Page

Searching there on TSaveDialog should bring up links to get to methods, properties, etc, ending at

https://docwiki.embarcadero.com/Libraries/Athens/en/Vcl.Dialogs.TOpenDialog.FilterIndex

   If LBRec.LBData = lbPicture then
     If LoadButton then
      begin
        OpenPicDia.FilterIndex := 1;
        OpenPicDia.InitialDir := GetCurrentDir;
        OpenPicDia.DefaultExt := '*.Jpeg';
        If OpenPicDia.Execute then
         begin
          Try
           Stream := TMemoryStream.Create;
           Stream.LoadFromFile(OpenPicDia.FileName);
           Str := Copy(ExtractFileExt(OpenPicDia.FileName), 1, 5);
           LBRec.FileExt := '     ';
           For I := 1 to length(Str) do LBRec.FileExt[I] := Char(Str[I]);
           LBRec.BlockSize := Stream.Size;
           LBRec.BlockPtr := Stream.Memory;
           Keys.PutRec(LastKeyName + LastRecName, LBRec);
          Finally
           Stream.Free;
          end;
         end;
      end else
         begin
            Keys.GetRec(LastKeyName + LastRecName, LBRec);
            Str := '      ';
            For I := 1 to 5 do Str[I] := AnsiChar(LBRec.FileExt[I]);
            SavePicDia.DefaultExt := '*' + Str;
            If SavePicDia.Execute then
              begin
               Try
                Stream := TMemoryStream.Create;
                Stream.Size := LBRec.BlockSize;
                CopyMemory(Stream.Memory, LBRec.BlockPtr, LBRec.BlockSize);
                Stream.SaveToFile(SavePicDia.FileName);
               Finally
                Stream.Free;
               end;
              end;
         end;

This my code
I identify Iā€™m dealing with a picture
then LoadButton separates a load from a save

my filter is loaded with
.jpeg;.gif;.jpg;.png;.bmp;.ico;.emf;.wmf;.tif;.tiff;.wbmp;.webp;*.svg
but I have no filter information
if its a *.PNG my code records the ā€˜.pngā€™ as the suggested extension but does not display it, it does not display the filter options ether.
sorry my code is not well laid out

but when I open a file store it and then return the data under another file name perfect - just does not give me the user helps in the dialogs

I also have difficulty with TOpenDialog. I want the diaolog to show all files with the extensions I provide like *.gbk, *.fbk, *.7z and *.zip. It does not seem to do that.

Iā€™m not the only one
lets see what Eivind Bakkestuen has to say

It requires the right separation syntax. Some components separate with , and some with ; and some with | Surprisingly there is no conformity - get the separator wrong and nothing works.

Set the Filter property correctly
e.g. Filter = ā€˜SQLiteDB (.db)|.db|SQLiteDB (.s3db)|.s3dbā€™
note the pipe symbols

It sure does need the right syntax.

But use the (filter) ā€˜editorā€™ (click on the ā€¦), and, if you still need help, thereā€™s a help button which quickly describes all the options.

so are you saying backup file(.gbk).gbk| firebird backup(.fbk)|.fbk|7zip file(.7z)|.7z|Zip File(.zip)| *.zip , will list all these files in the file list?

My tip for searching the official documentation on the web is to prefix your google search with ā€œdocwikiā€ like so.

While Iā€™m giving tips on googling, you can default all your google search results to the simple web only results view without the electricity guzzling AI generated pseudo-answer and other junk by following one of these methods. Iā€™m using method 2 and itā€™s been working great.

1 Like

You can only have one ā€œfilter typeā€ active at a time but each filter type can contain multiple extensions. The help explains it best:

Multiple filters should be separated by vertical bars. For example,
OpenDialog1.Filter := 'Text files (*.txt)|*.TXT|Pascal files (*.pas)|*.PAS';

To include multiple masks in a single filter, separate the masks with semicolons. This works both in the Object Inspector and in program code. For example,
OpenDialog1.Filter := 'Pascal files|*.PAS;*.DPK;*.DPR';

So what you want is ā€˜Backup file|*.gbk;*.fbk;*.7z;*.zipā€™. That is a single filter type ā€œbackup fileā€ that includes all files with those four extensions, so only files matching those will appear when the ā€œbackup fileā€ is selected in the dialog.

3 Likes

my mistake I forgot the vertical lines