Repository navigation
Error setting printer in Vcl.Printers during code coverage execution #41
Description
Activity
- Can you provide a minimal reproducible example of your code and the call to the code coverage tool? Op wo 24 jul 2024 14:55 schreef 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. — Reply to this email directly, view it on GitHub <#41>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ATDSYPXOH6HXX76ZHUNMKHTZN6P3RAVCNFSM6AAAAABLMNYQKSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQZDONJRGUYDOOI> . You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
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
BeginDocmethod:procedure TPrinter.BeginDoc; var DocInfo: TDocInfo; begin CheckPrinting(False); SetState(TPrinterState.psHandleDC); Canvas.Refresh; [...]The problem occurs in the
SetStatemethod.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.
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 -vCan 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.
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
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.