Page 1 of 1

Automatic screenshot on error

Posted: Wed Oct 13, 2010 2:12 pm
by Stokes
Hello,

What we want to do is to take a screenshot of our application when the user gets an error.

So in the exception handler we would put in some code like this:

activeWindow.screenShot(c:\Temp\Error_Screenshot_1.jpg);

before the error comes up on the screen it will take a screen shot of what the user was doing so they can send it through to us if they wish.

The error message will say something like:

"Send error detail and the screenshot to support? Yes/No"

Has this been done by anyone before? Looking forward to any good ideas someone may have.

Thanks for your time,


Sam

Re: Automatic screenshot on error

Posted: Wed Oct 13, 2010 3:55 pm
by torrie
I haven't specifically done this, we use CardSchema (http://www.jade.co.nz/jadecare/download.htm) which provides good logging on exceptions, if gives very good information about the call stack and current state of the application.

You could get a image of the current form using the Window::createPicture method. This would capture the active window, not the complete desktop. The ActiveForm method on the Application would let you get the form that the user had open.

Re: Automatic screenshot on error

Posted: Thu Oct 14, 2010 2:31 pm
by Stokes
Torrie, you are a legend!

This works well. Bug fixing will be much quicker now and there will be less going back and forth with the client trying to explain to them how to take a screen shot.

There are still a few things that I want to tidy up, my file is not deleting off the PC after I have used it and I want to give each of the screen shots and individual number. Both I will continue to work on for the rest of the day.

Here is the basic part of the code for anyone that is interested. This is within my exception handler:

Code: Select all

vars trFile : File; begin // Create the screenshot. create trFile transient; trFile.usePresentationFileSystem := false; trFile.fileName := "C:\temp6.bmp"; trFile.kind := File.Kind_Binary; // Open the file. trFile.open; // Read. trFile.writeBinary(app.activeForm.createPicture(false, true, 8)); // EMAIL THE ATTACHMENT ALONG WITH THE CALL STACK AND OTHER ERROR INFORMATION // Close the file. trFile.close; delete trFile;

Re: Automatic screenshot on error

Posted: Thu Oct 14, 2010 2:34 pm
by Stokes
oh and I will change it to create a .png or .jpg instead of a bitmap.

I will paste my final code in here once it is complete.

Re: Automatic screenshot on error

Posted: Thu Oct 14, 2010 3:33 pm
by Stokes
Final code:

Code: Select all

// Create the screenshot. create trFile transient; trFile.usePresentationFileSystem := true; trFile.fileName := app.getTempDir & "\SCREENDUMP.png"; trFile.kind := File.Kind_Binary; // Open the file. trFile.open; // Read. trFile.writeBinary(app.activeForm.createPictureAsType(false, true, 8, Window.PictureType_Png)); // Close the file. trFile.close; // Email the exception and screenshot to the specified email address. trSmtpManager.email(psToEmail, null, null, "Application exception on " & app.dbServerComputerName, psForEmail, String.None, trFile.fileName); trFile.purge; delete trFile;