Control file save dialog, different Windows versions
Hi all,
I am having a problem to DelphiScript a series of exports. Windows 8.1 and Windows 10 seem to use different file type entries in the "save as" dialogs of the OS: one shows the description, the other description plus pattern. When testing on different platforms the parameters past have to differ as a result.
First I tried to extract the available file types separated by CR/LF from the dialog object (GetPropertyValue) and loop over it, but the dialog object hierarchy differs, so I would need to hardcode the object access depending on the operating system. Then I tried exception handling: try description only, on exception try incl. pattern. However, this stops on the incorrect first try, see the code segments.
Is there any way to temporarily disable StopOnError or something similar, or is there a more elegant way to solve this in general, independant of the Windows version executing this? The next OS update or upgrade can otherwise easily make the script invalid. Alternatively I either create a config per OS test environment, or I would need to switch to an OS-independant file dialog with all its style and layout issues.
procedure _exportOne (AGrid: OleVariant; AOutFile: string; AType, ATypeAlt: string);
begin
AGrid.ClickCellR(0, 0);
AGrid.PopupMenu.Click('[1]');
try
LFH.dlgSpeichernUnter.SaveFile (AOutFile, AType);
except
LFH.dlgSpeichernUnter.SaveFile (AOutFile, ATypeAlt);
end;
end;
procedure _exportSet (AOutBase: string; AGrid: OleVariant);
begin
//-- save report in all formats.
_exportOne (AGrid, AOutBase+'.txt', 'ASCII', 'ASCII (*.txt)');
_exportOne (AGrid, AOutBase+'.xlsx', 'Excel Document', 'Excel Document (*.xls)');
_exportOne (AGrid, AOutBase+'.html', 'HTML', 'HTML (*.html)');
end;
Any hints welcome, thanks in advance.
Best regards, and have a Merry Christmas!
Matthias
Hi Matthias,
FileType is an optional parameter of the SaveFile method and usually the file is saved with the correct extension as long as you provide it in the file name. So, any problems if you leave the FileType parameter with the default -1 value (or omit it at all as I did in my projects)?