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

Memo contents appears in text file

edited November 2001 in General
I have a report which works nicely when previewed and printed.
It has many labels and 1 memo.

However, when the user takes the option of outputting the report to a text
file, things go wrong.

According to the 'Developer's Guide' the contents of RichText and Memodo not
get output to a text file. Curiously I get "some" of the memo output. (This
is good as I would prefer this to happen!)
The memo contents is 4 lines. What gets output is not 0 lines as I would
expect, but lines 1, 2, 4, 1, 2, 3, 4.

I would appreciate tips on how I can block this output.

Regards, Peter Evans

Comments

  • edited November 2001
    The memo output is tricky, since the lines were wrapped during generation
    for the printer canvas' capabilities. Set the Save property to false for
    the memo control and it won't get written to the text file.

    If you don't want the user to ever be able to print a memo to file, then you
    can set this up programatically. You could loop through all of the objects
    in the report before the report prints, and check for TppMemo objects and
    set their Save property to False. There is an article in the Tech-Tips
    newsgroup in the Code Based thread - 'Report Object Loop.'

    The best output for a memo will come when you change the report so that it
    specifically is designed to print to text file. You may want to create a
    duplicate report that is printed to text file, and another one for the
    printer/other devices. Set TppReport.PrinterSetup.PrinterName to "Screen".
    At that point you can choose the "Courier" screen font (you may have to exit
    Delphi and get back in before it shows up). Set all of your text to Courier
    (screen font) 12 point and everything should work.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited November 2001
    I am still struggling with the Memo.

    I have a report which works nicely when previewed and printed. It has many
    labels and 1 memo.
    One label is on Header Band. One label is on Footer Band. Many labels and
    one memo is on the
    one Detail Band.

    I am using demo version 6.02 for Delphi 4.

    Choose File | Print to File Setup. The list of available controls for the
    Detail Band only
    lists the labels. It does not list the one memo. This is as it should be
    according to the
    "Developer's Guide". The Guide says that contents of RichText and Memo do
    not get output
    to a textfile.

    However, the memo (or parts of it) do get output to the text file. I am
    confused as to why
    the memo gets output when it not one of the "Available Controls", nor does
    it appear in the
    list of "Selected Controls".

    I tried setting the Save property to false for the memo, as you suggested.
    However there is
    no Save property in the "Object Inspector" that I could see. Also tried
    programmatically getting
    such a property using Delphi's code completion. There is no property. There
    is such a property
    for Label.

    Is demo version 6.02 the latest version?

    I did notice that the dialog "Print to File Setup" is different to the
    "Developer's Guide".
    My dialog has an additional edit box named "Save Length". So I suspect I
    don't have the correct
    version.

    I welcome further advice on solving these problems.


    Regards, Peter Evans
  • edited November 2001
    It is our fault on not getting the DevGuide updated. Previously, the memo
    was never supported to be rendered into a text file. However, the
    functionality was added to be able to support this if the text was
    configured correctly so that it could map to the character grid of the file
    when the text was wrapped by the report engine.

    There are two text file output devices- the delimited (comma, tab...) text
    file and the Report Emulation text file. The Save properties affect which
    text controls are printed in the delimited text file. They have no effect on
    the Report Emulation text file. The Report Emulation text file will attempt
    to render as much text as it can to the text file. The only way you can
    control which text prints to the file is to use the Report.BeforePrint event
    and check the Report's DeviceType property and set the visibility of the
    memo to false if it isn't to be generated to the Report Emulation text file.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited November 2001
    Still struggling...

    I decided to suppress the memo to the Report Emulation Text File.

    This is what I coded (in ppReport1BeforePrint(Sender: TObject)) ::-

    IF ppReport1.DeviceType = ppTypes.dtReportTextFile THEN BEGIN
    memoName.Visible := False {do not output}
    END
    ELSE
    memoName.Visible := True;

    The memo was still output. I then coded ::-

    IF ((ppReport1.DeviceType = ppTypes.dtReportTextFile) OR
    (ppReport1.DeviceType = ppTypes.dtTextFile )) THEN BEGIN
    memoName.Clear;
    memoName.Visible := False {do not output}
    END
    ELSE
    memoName.Visible := True;

    The memo is still output.
    What am I doing wrong in the code?

    Regards, Peter Evans
  • edited November 2001
    Unfortunately still struggling...

    I decided to suppress the memo to the Report Emulation Text File.

    This is what I coded (in ppReport1BeforePrint(Sender: TObject)) ::-

    IF ppReport1.DeviceType = ppTypes.dtReportTextFile THEN BEGIN
    memoName.Visible := False {do not output}
    END
    ELSE
    memoName.Visible := True;

    The memo was still output. I then coded ::-

    IF ((ppReport1.DeviceType = ppTypes.dtReportTextFile) OR
    (ppReport1.DeviceType = ppTypes.dtTextFile )) THEN BEGIN
    memoName.Clear;
    memoName.Visible := False {do not output}
    END
    ELSE
    memoName.Visible := True;

    The memo is still output.
    What am I doing wrong in the code?

    Regards, Peter Evans
  • edited November 2001
    Your code looks ok. Place breakpoint in there to make sure that it is
    getting calledand set to visible false. Make sure the event handler is
    assigned if you are loading a report template .rtm. I dropped a memo in a
    report and set its visibility with the following code and it didn't print to
    the report text file when Memo.Visible=False:


    uses
    ppTypes;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    ppReport1.Print;
    end;

    procedure TForm1.ppReport1BeforePrint(Sender: TObject);
    begin

    if (ppReport1.DeviceType = dtReportTextFile) then
    ppMemo1.Visible := False
    else
    ppMemo1.Visible := True;

    end;


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited November 2001
    Thank you for giving me a clear example to work with.

    I followed your lead and placed a ShowMessage() in my code ::-

    ShowMessage(ShowMessage('The ppReport1.DeviceType is ' +
    ppReport1.DeviceType);

    This gave the following ::-

    when Preview
    ...is Screen
    when Print
    ...is Printer
    when Report Emulation
    ...is Printer

    So my code detected that the Property DeviceType is not being set.

    I then followed your lead and did the short test program you outlined.
    (It is necessary to set Property AllowPrintToFile = True)

    My results were different to you. They were exactly the same as my original
    project.

    I then set Property DeviceType = ReportTextFile. The program worked.

    It seems to me that ReportBuilder is not setting the Property DeviceType
    when the user
    clicks on the "Print to File" option.

    Is this a bug? If not, how to I code around the problem?


    Regards, Peter Evans
  • edited November 2001
    Resending my Post of 11 Nov.
    I am completely stuck with this problem.

    original
  • edited November 2001
    Sorry for the delay on this, here's the code you'll need since the print
    dialog object is where the device type is getting set:

    if (ppReport1.DeviceType = dtReportTextFile) then
    ppMemo1.Visible := False

    else if (ppReport1.PrintDialog <> nil) and
    (ppReport1.PrintDialog.DeviceType = dtReportTextFile) then
    ppMemo1.Visible := False

    else
    ppMemo1.Visible := True;



    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited November 2001
    Phew (wiping sweat from brow), now works!
    Regards, Peter Evans
This discussion has been closed.