Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

BeforePrint event

edited August 2009 in General
Delphi 2009 and RBuilder 11.05

a) I am sending an email via an RBuilder report and attaching the report as
a PDF. Unfortunately, I have to use MAPI vs SMTP, because the Indy10
attaches the report as a .dat and not a .pdf.

b) The ppReport is on a separate form created when the report is created.

c) Because I have to use MAPI, the user must enter the email body text via a
wwMemoDialog. This works if I have the user enter the text via a procedure
"RunMAPIReport" called in the forms OnCreate event. See code (A) below.

However, I would like the user to be able to enter the email body text from
the ppReport1.BeforePrint event. This would avoid asking the question
regarding email body text if the report output was being sent to the printer
and not to the MAPI client. See Code (B) below. Unfortunately, code B does
not work. Does anyone have a suggestion as to how to resolve this issue?

Code A
procedure TRBReportRequestLetter2.RunMAPIReport;
begin
with ppReport1 do
begin
if MessageDlg('Do you wish to send an email with text in the email
body?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
if wwMemoDialogEmailBody.Execute = True then
begin
EmailSettings.Body := wwMemoDialogEmailBody.Lines;
end
else
begin
EmailSettings.Body := nil;
end;
end;

EmailSettings.ShowEmailDialog := False;
EmailSettings.PreviewInEmailClient := False;
EmailSettings.Enabled := True;

// EmailSettings.FileName := 'Request For Services';
EmailSettings.Subject := formRequestForServices.Caption;

EmailSettings.Recipients.Clear;
if tempToEMailAddress <> '' then
begin
EmailSettings.Recipients.Add(tempToEMailAddress);
end;

EmailSettings.CarbonCopy.Clear;
if tempCCEMailNumber >= 1 then
begin
EmailSettings.CarbonCopy := tempStringListCCAddress;
end;

Print;
end;
Close;
end;

Code B
procedure TRBReportRequestLetter2.ppReport1BeforePrint(Sender: TObject);
begin
if tempMemoPass = True then
begin
if ppReport1.DeviceType = dtPrinter then
begin
// showmessage('Printer');
end
else
begin
if ppReport1.DeviceType = dtPDF then
begin
if wwMemoDialogEmailBody.Execute = True then
begin
ppReport1.EmailSettings.Body :=
wwMemoDialogEmailBody.Lines;
end;
end;
end;
end;
end;

TIA

John

Comments

  • edited August 2009
    Hi John,

    The BeforePrint event fires too late to alter the EmailSettings.Body
    property. Are you allowing your users to press the email button in the
    Preview window? If so, I would recommend taking control of the OnClick
    event of that button, then gathering the body information from there and
    sending the email manually in code.

    uses
    ppPrvDlg;

    procedure TForm1.ppReport1PreviewFormCreate(Sender: TObject);
    begin
    TppPrintPreview(ppReport1.PreviewForm).EmailButton.OnClick :=
    EmailClickEvent;
    end;

    procedure TForm1.EmailClickEvent(Sender: TObject);
    begin
    if wwMemoDialogEmailBody.Execute = True then
    ppReport1.EmailSettings.Body := wwMemoDialogEmailBody.Lines;

    ppReport1.SendMail;
    end;

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2009
    Nico

    Excellent - Thanks

    John


This discussion has been closed.