The Open/SaveDialogs have an event
OnTypeChange which fires when a different file type is selected in the dialog. If you have a flexible Filter list then you must determine the filter expression which belongs to the new type. Note that, against the usual convention, the FilterIndex begins with the value 1 here (not with 0):
procedure TForm1.OpenDialog1TypeChange(Sender: TObject);
var
sa: TStringArray;
index: Integer;
begin
sa := OpenDialog1.Filter.Split('|');
index := (OpenDialog1.FilterIndex - 1) * 2;
OpenDialog1.DefaultExt := sa[index];
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
with OpenDialog1 do begin
Filter := 'CSV files (*.csv)|*.csv|Excel files (*.xls)|*.xls|Open Document Files (*.ods)|*.ods';
DefaultExt := '.csv';
FilterIndex := 1;
FileName := '';
if Execute then
Edit1.Text := FileName;
end;
end;
I tested this works on Windows, and I don't see a reason that it should not work on Mac. The code is correct as long as a single extension is assigned to each file type (i.e. ('*.xls' is ok, but '*.xls;*.xlsx' is not) - you certainly can find the code for multiple extension by yourself.