Forum Discussion

prognase's avatar
prognase
Occasional Contributor
10 years ago

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)?

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    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)?

    • prognase's avatar
      prognase
      Occasional Contributor

      Hi Alex,

       

      thanks for the suggestion. Didn't know that file type is an optional parameter or that there are overloaded functions. Do you know by any chance where I could find such information? I guess MSDN or similar, but as I am a Delphi guy I have no real knowledge how to find my way there.

       

      Currently my Delphi code takes the file type which is not switched when calling from "outside" this way:

       

      fileName := SAVEDLG_Grid.FileName;
      case SAVEDLG_Grid.FilterIndex of
        1: saveFormat := gsfASCII;
        2: saveFormat := gsfCSV;
        3: saveFormat := gsfXLS;
        4: saveFormat := gsfDoc;
        5: saveFormat := gsfHTML;
        else saveFormat := gsfUnknown;
      end;

       

      But that code I can change easily and derive type from variable fileName.

       

      Thanks for the solution, and if you know MSDN or similar starting point, would be thankful!

       

      Cheers,

      Matthias

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi Matthias,

         

        .FileName() in your code is not something provided by MS, but a method by TestComplete. You can find its description at https://support.smartbear.com/viewarticle/73794/ (or by pressing F1 in TestComplete code editor with the cursor positioned somewhere within the 'FileName' token ;) ).

        Slightly off topic, but I consider documentation by SmartBear for TestComplete (as well as for AQtime, LoadComplete) to be one of the best in the industry. (Well, MSDN contains more information, but it is supported by MS with incomparable resources...) TestComplete's documentation contains not only description of the methods provided by TestComplete, but also generic descriptions and recommendations that really help to understand the product better. I used to go through their documentation from time to time to refresh my memory and can safely recommend to read their documentation to anyone else.

        Also you may find something useful for you at https://support.smartbear.com/screencasts/testcomplete/

         

        As for your code and assuming that the tested application does not depend on the value selected for file type (and this is usually the case), I think that you can easily omit the saveFormat parameter as long as fileName one contains the fully qualified file name (path, name and extension).

  • In our testing, we decided to just get the text value of the "Type" drop-down box, assign it to a variable, and then pass it back in when interacting with the dialog.

     

    Hope this helps.

     

    Matt

    • prognase's avatar
      prognase
      Occasional Contributor

      Hi Matt,

       

      could you elaborate a bit more? What you do seems to be like what I tried with reading all dropdown list values for file types and then looping over that, i.e. always having the right version with or w/o extension in the string.

       

      However, the objects and their child structure differ between the 10 and 8.1 versions, so I would need to know the exact "paths" for each of the dropdowns. Making it more complicated, my license for TC is on 10, TE is on 8.1, and in TE there is no recording, so no easy capturing of the components and their attributes.

       

      Very much interested how you approached this issue.

       

      Thanks,

      Matthias