Root > How to... > ...save report instead of sending it?

...save report instead of sending it?

Previous pageReturn to chapter overviewNext page   
1. If you are looking for saving local reports - we recommend that you use "Save bug report to file" option. See also: How to get file name for bug report? How to add/save exception to a log?
2. If you are looking for sending errors recovery - we recommend that you use "Save bug report copy to My Documents folder" and/or "Copy bug report to clipboard" options. See also: Dealing with send failures.

 

Full bug report (with screenshots, attached files, previous reports; it is usually stored packed inside a single .elp file) is generated only for sending. You may wish to capture this file into local folder or network share, or insert it into database.

 

 

Option 1: Silent, automatic, without UI

Set up sending as usual and use this code:

 

uses
  ESend,    // for TELUniversalSender and RegisterSender
  EModules, // for CurrentEurekaLogOptions
  ETypes;   // for constants
 
type
  // Create a new "send engine".
  // It will be dummy that will perform no actual sending.
  // Instead - it will save all files attachments to folder.
  TDummySender = class(TELUniversalSender)
  public
    function SendMessage: TResponse; override;
  end;
 
{ TDummySender }
 
function TDummySender.SendMessage: TResponse;
var
  X: Integer;
begin
  // Copy all files attachments to some folder.
  // Of course, folder must exist and be writable.
  // Usually there is only one file (.elp), but it can be few files - 
  // depends on your project options
  for X := 0 to AttachedFiles.Count - 1 do
    CopyFile(PChar(AttachedFiles[X]), 
      PChar('N:\BugReports\' + ExtractFileName(AttachedFiles[X])), 

      False);
 
  // Indicate that "send" was a failure.
  // This will cause EurekaLog to try next send method (if it was set up).
  // If there is no next method - a send error will be reported.
  Finalize(Result);
  FillChar(Result, SizeOf(Result), 0);
  Result.SendResult := srUnknownError;
  // Result.ErrorMessage := ''; // <- you can also customize error message
  // to show to user (if there is no next method configured)
end;
 
initialization
  // Register our class to be used by EurekaLog
  RegisterSender(TDummySender);
  // Ask EurekaLog to send via our class first
  CurrentEurekaLogOptions.AddSenderClass(TDummySender.ClassName, 
    0 { <- our class will be invoked first });
end.

 

Please note that bug report will be saved only if sending is performed. E.g. either user clicks on "Send report" button in dialog, or you set up automatic sending without user consent. If you want to always save .elp file (even if user decided not to send report) - please, see this example.

 

 

Option 2: With visual UI for user

Do not set up sending in your application, it will be ignored. You may modify code below for your specific needs.

 

uses
  ESend,    // for TELUniversalSender and RegisterSender
  EModules, // for CurrentEurekaLogOptions
  ETypes;   // for constants
 
type
  // Create a new "send engine".
  // It will be dummy that will perform no actual sending.
  // Instead - it will save all files attachments to folder.
  TSaveToFile = class(TELUniversalSender)
  public
    function SendMessage: TResponse; override;
  end;
 
{ TSaveToFile }
 
function TSaveToFile.SendMessage: TResponse;
 
  // This function saves bug report into folder
  // You may alter this code to upload bug report to database
  // or do whatever you want
  procedure CopyBugReport(const ADestFileName: String);
  var
    X: Integer;
    TargetPath: String;
  begin
    // Copy primary attachment (.elp bug report)
    Win32Check(CopyFile(PChar(AttachedFiles[0]),
      PChar(ADestFileName), False));
 
    if AttachedFiles.Count = 1 then
      Exit;
 
    // Copy all remaining files attachments to some folder.
    // Usually there is only one file (.elp), but it can be several files -
    // depends on your project options and your customization code
    TargetPath := ExtractFilePath(ADestFileName);
    for X := 1 to AttachedFiles.Count - 1 do
      Win32Check(CopyFile(PChar(AttachedFiles[X]),
        PChar(TargetPath + ExtractFileName(AttachedFiles[X])), False));
  end;
 
var
  TargetFile: String;
begin
  Finalize(Result);
  FillChar(Result, SizeOf(Result), 0);
  try
    if AttachedFiles.Count = 0 then
    begin
      // We should not really get there, this is just fail-safe check
      Result.SendResult := srNoExceptionInfo;
      Exit;
    end;
 
    // Save bug report:
    TargetFile := 'N:\Reports\' + ExtractFileName(AttachedFiles[0]);
    CopyBugReport(TargetFile);
 
    // Indicate that "send" was a success.
    Result.SendResult := srSent;
 
  except
    on E: Exception do
    begin
      // Indicate that "send" was a failure.
      Result.SendResult := srUnknownError;
      if E is EOSError then
        Result.ErrorCode := Integer(EOSError(E).ErrorCode);
      Result.ErrorMessage := E.Message;
    end;
  end;
end;
 
initialization
  // Register our class to be used by EurekaLog
  RegisterSender(TSaveToFile);
 
  // Set our sender as the one and only - this is important
  CurrentEurekaLogOptions.SenderClasses := TSaveToFile.ClassName;
 
  // Change "Send" button to "Save" button in all dialogs
  CurrentEurekaLogOptions.CustomizedTexts
    [mtMSDialog_SendButtonCaption] := 'Save Report';
  CurrentEurekaLogOptions.CustomizedTexts
    [mtMSDialog_NoSendButtonCaption] := 'Don''t Save';
  CurrentEurekaLogOptions.CustomizedTexts
    [mtDialog_SendMessage] := 'Save this report into file';
end.

 

If you wish to ask user where to save bug report file - use this code:

 

uses
  Dialogs, // for TSaveDialog
  ActiveX, // for CoInitialize
  ESysInfo, // for GetFolderPersonal
// ...
 
type
  TSaveToFile = class(TELUniversalSender)
  private
    procedure Dummy(Sender: TObject);
  // ...
  end;
 
// ...
 
var
  SaveDialog: TSaveDialog;
  TargetFile: string;
  TargetExt: string;
  NeedToUninitialize: Boolean;
begin
  // ...
 
    // Ask where to save bug report
 
    // Send is performed in background thread by default 

    // (use options to change that)
    // We need to initialize COM for use in

    // modern file dialogs (Vista+)
    NeedToUninitialize := Succeeded(CoInitialize(nil));
    try
 
      SaveDialog := TSaveDialog.Create(nil);
      try

        // Usually this is primary bug report file
        TargetFile := ExtractFileName(AttachedFiles[0]); 

        // Can be .el or .elp - depends on your options
        TargetExt := ExtractFileExt(TargetFile); 
 
        SaveDialog.Title := 'Save Bug Report';

        // "My Documents"
        SaveDialog.InitialDir := GetFolderPersonal; 
        SaveDialog.FileName := TargetFile;
        SaveDialog.DefaultExt := TargetExt;
        SaveDialog.Filter := 

          'Bug Reports|*' + TargetExt + '|All Files|*.*';
        SaveDialog.FilterIndex := 0;
        SaveDialog.Options := [ofOverwritePrompt,

          ofHideReadOnly,ofPathMustExist,ofNoReadOnlyReturn,

          ofEnableSizing,ofDontAddToRecent];
 
        // Assigning OnIncludeItem, OnShow or OnClose will

        // turn off Vista dialogs (which requires COM)
        // Classic dialogs do not require COM
        if not NeedToUninitialize then
          SaveDialog.OnClose := Dummy;
 
        if SaveDialog.Execute then // <- this may fail without

        // COM initialization - depends on your IDE and OS
          CopyBugReport(SaveDialog.FileName);
 
      finally
        FreeAndNil(SaveDialog);
      end;
    finally
      if NeedToUninitialize then
        CoUninitialize;
    end;
 
// ...
 
procedure TSaveToFile.Dummy(Sender: TObject);
begin
  // Do nothing
end;

 

 

See also:




Send feedback... Build date: 2024-09-30
Last edited: 2023-08-09
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/how_to_save_report_instead_sending.php