Home General

Access violation when sending emails.

edited September 2015 in General
Hi,

Using RB15.05, Delphi 2009.

We have an odd problem that appears to be connected to registering SMTP
plugins and the creation and destruction of forms. What happens is this:

1. We create a form containing a TppReport object.
2. Preview the report.
3. Click the email button.
* This calls our own inherited version of TppPreview which overrides
SendEmail.
* SendEmail calls TppSMTPPlugin.RegisterClass(TppSMTPMapi);
* SendEmail calls Inherited
* SendEmail calls TppSMTPPlugin.UnRegisterClass(TppSMTPMapi);

4. The email sends successfully.
5. Close (and destroy) the form holding the report.
6. Repeat steps 1 - 3, but this time the call to Inherited throws an
access violation. We don't understand why. If I break on exceptions, the
cursor appears to be somewhere down in the XLS generation routines,
which is odd as the report output format is PDF. It only seems to enter
this routine the second time. The problem only occurs if the form with
the report on is destroyed and then re-created before running the report
the second time. If you simply click email and then close the preview
and then preview again it works.

The code for our overridden SendEmail is this:

procedure TWCBSPreview.SendEmail;
var TempFileName : string;
begin

TppSMTPPlugIn.RegisterClass(TppSMTPMapi);

TppReport(Report).EmailSettings.FileName := 'c:\Report.pdf';

try
inherited;

finally
TppSMTPPlugIn.UnRegisterClass(TppSMTPMapi);
end;

end;

Are we doing something wrong or missing a step? We can't put the calls
to register and unregister in the initialization / finalization because
depending on some circumstances we sometimes use a different plugin
(I've omitted the code for that, but it makes no difference to the outcome).

Thanks,

Steve Branley

Comments

  • edited September 2015
    Hi Steve,

    1. Are you able to recreate this issue with the built-in preview and a
    simple example, or does it only occur with your custom preview?

    2. If you are emailing PDF files, your code should not be executing XLS
    code. Check the call stack and see where this XLS call is originating from.

    3. Inside your overridden SendEmail routine, try making a direct call to
    Report.SendMail rather than calling Inherited and see if that makes a
    difference.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2015
    Hi Nico,

    This only occurs with the custom preview. It appears to be linked to our
    registering and unregistering of the SMTP plugin.

    It definitely shouldn't be doing anything XLS related, but so far I've
    not had much luck with the call stack. I'll persevere.

    I'll try calling report.sendmail directly and see what happens.

    Thanks for the reply,

    Steve


  • edited September 2015
    Hi Nico,

    Sorry to reply to this again, but I'm getting nowhere. If I trace into
    ppPreview, I get to the point where it calls FReport.SendMail and it
    access violation. I don't know why. I have a breakpoint within
    TppProducer.SendMail and it never hits it. I don't know if there's an
    event that is called before it gets to ppProducer.SendMail, but it just
    doesn't seem to ever get there.

    Calling report.SendEmail directly doesn't work, by the way.

    Any other ideas? I can reproduce the problem quite easily.

    Thanks,

    Steve

  • edited September 2015
    Hi Steve,

    Being that you can only create this issue with your custom preview, it
    is unlikely that I will be able to recreate it here.

    Please create a minimal example using only RB and Delphi components that
    shows this error and send it to support@digital-metaphors.com in .zip
    format and I'll test it with the latest version of ReportBuilder.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.