Skip to content

Error setting printer in Vcl.Printers during code coverage execution #41

Description

@rogerio1105

When running the code coverage on the application I'm testing, an error occurs when attempting to set the printer during a print attempt. This issue only happens when the application is run with code coverage enabled.

To provide more detail, the problem occurs in the method from the Vcl.Printers library, specifically in the procedure TPrinter.BeginDoc. The issue arises when executing SetState(TPrinterState.psHandleDC);. The error message returned is: "Printer selected is not valid."

I start the code coverage using a batch file, passing the necessary parameters. I suspect that the issue may be related to the command prompt not recognizing the default printer when running the application in this instance.

I would appreciate assistance with this situation. Is there any configuration or parameter that I should set for the code coverage to resolve this problem?

Thank you.

Activity

  1. Laurensvanrun commented on Jul 24, 2024

    @Laurensvanrun
    Contributor
  2. rogerio1105 commented on Jul 25, 2024

    @rogerio1105
    Author

    Of course. The call in the program is quite simple.

    uses
      Vcl.Printers;
    
    procedure btnTestClick(Sender: TObject);
    begin
      Printer.BeginDoc;
    end;
    

    This is the call.

    The BeginDoc method:

    procedure TPrinter.BeginDoc;
    var
      DocInfo: TDocInfo;
    begin
      CheckPrinting(False);
      SetState(TPrinterState.psHandleDC);
      Canvas.Refresh;
      [...]
    

    The problem occurs in the SetState method.

    This issue arises only when running the application with code coverage enabled. It results in the error message: "Printer selected is not valid."

    I'm running this on Delphi tokyo and Windows.

  3. rogerio1105 commented on Jul 25, 2024

    @rogerio1105
    Author

    Here is the command line used to execute the code coverage, which is included in a batch file:
    "C:\CodeCoverage\CodeCoverage.exe" -m "C:\Contabil\wcont.map" -e "C:\Contabil\wcont.exe" -uf "C:\Users\rogerio.pack\temp\Wcont\Units.lst" -spf "C:\Users\rogerio.pack\temp\Wcont\Diretorios.lst" -od "C:\Users\rogerio.pack\temp\Wcont" -xml -html -xmllines -twd -v

  4. Laurensvanrun commented on Jul 25, 2024

    @Laurensvanrun
    Contributor

    Can you attach a ZIP with the smallest possible reproduction? So, a separate Delphi program which reproduces exactly the problem your describe (but with not any other code to exclude other issues in your code). Which compiles and generates the map file you use and with the corresponding *.lst files you use in your batch file. Not just some code snippets :-)

    That way I can reproduce it after my holiday and see what might go wrong.

  5. rogerio1105 commented on Jul 26, 2024

    @rogerio1105
    Author

    Good afternoon, sorry for the delay, but I have added an example in the attached zip file. In the "CodeCoverage" folder, you will find the necessary files and the batch file. If you need anything else, please let me know.
    exemplo.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions