rave reports , print memo field

how to add print of a memo field (many lines incl. CR) to this evaluation program

would like to print the contents of biolife.db  with RAVE and Delphi
unit Unit_LibraryReportTool;
{ *****************************************************************************
  *
  *
  *       DEMO  DUMP the Content of the Borland biolife.db with RAVE reports
  *
  *****************************************************************************}

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls,  DB, Grids,
  DBGrids, DBTables, ComCtrls, ExtCtrls,

  //  RAVE
  RpRave, RpDefine, RpCon, RpConDS,


  RpBase, RpSystem, RpConBDE ;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Exit1: TMenuItem;
    ReportTable: TTable;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    LoadLibararyDB1: TMenuItem;
    MainStatusBar: TStatusBar;
    Report1: TMenuItem;
    StartReport1: TMenuItem;
    Panel1: TPanel;
    Label1: TLabel;
    ListBox1: TListBox;
    RvTableConnection1: TRvTableConnection;
    LibRvSystem: TRvSystem;
    RvProject1: TRvProject;
    ableReport1: TMenuItem;
    procedure Exit1Click(Sender: TObject);
    procedure LoadLibararyDB1Click(Sender: TObject);
    procedure StartReport1Click(Sender: TObject);
    procedure LibRvSystemPrint(Sender: TObject);
    procedure LibRvSystemAfterPreviewPrint(Sender: TObject);
  private
    { Private-Deklarationen }
    FLibraryFilename   :  String;     ///  the name of the table for report
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Exit1Click(Sender: TObject);
begin
      close;
end;

procedure TForm1.LoadLibararyDB1Click(Sender: TObject);
begin
      FLibraryFilename := 'e:\biolife.db';

      ReportTable.Active := false;

      ReportTable.TableName := FLibraryFilename;

      ReportTable.Active := true;


end;

procedure TForm1.LibRvSystemAfterPreviewPrint(Sender: TObject);
begin

end;

///
///
///
procedure TForm1.LibRvSystemPrint(Sender: TObject);
const tab1=0.2;
      tab2=1.7;
      tab3=3.2;
      tab4=4.0;
      tab5=5.0;

var    i          :  Integer;
       dbstring   :  String;
begin
      with Sender as TBaseReport do
        begin

        SetFont('ARIAL',15);

        Print ('Welcome to the rave demo report project (printing biolife.db) !!');




        GoToXY(1,1);
        NewLine;
        NewLine;

        ClearTabs;
        SetTab(tab1,pjLeft,tab2, 0,0,0);
        SetTab(tab2,pjLeft,tab3, 0,0,0);
        SetTab(tab3,pjLeft,tab4, 0,0,0);
        SetTab(tab4,pjLeft,tab5, 0,0,0);

        Bold := true;
        SetFont('ARIAL',10);


        PrintTab('Species No');
        PrintTab('Category');
        PrintTab('Common_Name');
        PrintTab('species Name ');

        Newline;
        Bold := false;

        for i:= 1 to ReportTable.RecordCount  do
             begin


             canvas.brush.color := clred;
             rectangle (0.1, 0.1, 6, 6);


             newline;

             dbstring := ReportTable.FieldByName('Species No').asstring;
             PrintTab(dbstring);

             dbstring := ReportTable.FieldByName('Category').asstring;
             PrintTab(dbstring);


             dbstring := ReportTable.FieldByName('Common_Name').asstring;
             PrintTab(dbstring);


             dbstring := ReportTable.FieldByName('Species Name').asstring;
             PrintTab(dbstring);


             NewLine;

             ReportTable.Next;



             ///   1 record on 1 page
             NewPage;

             end;








        end;
end;

procedure TForm1.StartReport1Click(Sender: TObject);
begin
      ////

      MainStatusBar.SimpleText := 'Start Simple Database Documentation';


      LibRvSystem.Execute;


      MainStatusBar.SimpleText := 'Documentation -> done ! ';
end;

end.

Open in new window

LVL 8
BdLmAsked:
Who is Participating?
 
jimyXCommented:
When you double click on the TTable you get a window for the fields from your database once you click on the "Notes" field in that list go to the Object Inspector and see what is the Name of that field then assign in to your MemoField

Memobuf.Field := FieldNotesName;

Most likely is going to be the default which is: TableName + FieldName:
Memobuf.Field := ReportTableNotes;


And if you want to use the Method FieldByName then:
Memobuf.Text := ReportTable.FieldByName('Notes').AsString;
0
 
jimyXCommented:
You can use TDBMemoBuf:
uses RPMEMO, RPDBUTIL;
...
var
  MemBuf: TDBMemoBuf;
...
  MemBuf := TDBMemoBuf.Create;
  with ReportTable do
    begin
      if not Active then
        Open;
        First;
        gYPos := gYPos + 0.5;
        while not eof do
          begin
            GoToXY(5.0,gYPos);
            MemBuf.PrintStart := 6.0;
            MemBuf.PrintEnd := 10.5;
            MemBuf.Field := (FieldByName('Notes') as TMemoField);
            MemBuf.NoCRLF := False;
            for I := 1 to 5 do
              begin
                dbstring := GetMemoLine(MemBuf,XEOL);
                if dbstring <> '' then
                  begin
                    gYPos := gYPos + 0.15;
                    GoToXY(6.0,gYPos);
                    PrintLn(dbstring);  // PrintTab
                  end;
              end;
            gYPos := gYPos + 0.2;
            Next;
          end;
        MemBuf.Free;
    end;
...

Open in new window

http://www.delphipages.com/forum/showthread.php?t=208806
PS: The above code is not tested, you might need to adjust it to match your requirements.
0
 
BdLmAuthor Commented:
dbstring := GetMemoLine(MemBuf,XEOL);

this line of code I can't understand
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jimyXCommented:
GetMemoLine is a method in the class RPMemo.
function GetMemoLine( MemoBuf: TMemoBuf; var EOL: boolean): string;

You can read more about it here:
http://www.nevrona.com/files/rppro.pdf

I quote from the above book:
"This method will return a single line from the memo buffer each time it is called.
You can print the memo buffer line by line by placing this function inside a Println
statement. EOL returns true when it encounters a carriage return or the end of the
memo buffer."
0
 
BdLmAuthor Commented:
the code returns chinese memo text .....  can you see the bug ???
///
///
///
procedure TForm1.LibRvSystemPrint(Sender: TObject);
const tab1=0.2;
      tab2=1.7;
      tab3=3.2;
      tab4=4.0;
      tab5=5.0;

var    i          :  Integer;
       dbstring   :  String;
begin


     LibRvSystem.SystemPrinter.Orientation := poLandScape; // or poPortrait





      with Sender as TBaseReport do
        begin






        SetFont('ARIAL',15);

        Print ('Welcome to the rave demo report project (printing biolife.db) !!');




        GoToXY(1,1);
        NewLine;
        NewLine;

        ClearTabs;
        SetTab(tab1,pjLeft,tab2, 0,0,0);
        SetTab(tab2,pjLeft,tab3, 0,0,0);
        SetTab(tab3,pjLeft,tab4, 0,0,0);
        SetTab(tab4,pjLeft,tab5, 0,0,0);

        Bold := true;
        SetFont('ARIAL',10);


        PrintTab('Species No');
        PrintTab('Category');
        PrintTab('Common_Name');
        PrintTab('species Name ');

        Newline;
        Bold := false;

        for i:= 1 to ReportTable.RecordCount  do
             begin


             canvas.brush.color := clred;
             rectangle (0.1, 0.1, 6, 0.2);


             newline;

             dbstring := ReportTable.FieldByName('Species No').asstring;
             PrintTab(dbstring);

             dbstring := ReportTable.FieldByName('Category').asstring;
             PrintTab(dbstring);


             dbstring := ReportTable.FieldByName('Common_Name').asstring;
             PrintTab(dbstring);


             dbstring := ReportTable.FieldByName('Species Name').asstring;
             PrintTab(dbstring);


             NewLine;


             RavePrintDBmemo(3,5, 1, (sender as Tbasereport) );




             ReportTable.Next;



             ///   1 record on 1 page

             NewPage;

             end;








        end;
end;


procedure TForm1.RavePrintDBmemo ( PrintStart, PrintEnd : Real; YPos : Real ; AReport : TBasereport ) ;
var  MemBuf   : TDBMemoBuf;
     dbstring : String;
     i        : Integer;
     isEOL    : Boolean;
begin
  MemBuf := TDBMemoBuf.Create;
  with ReportTable do
    begin

        YPos := YPos + 0.5;

        AReport.GoToXY(PrintStart,YPos);
        MemBuf.PrintStart := PrintStart;
        MemBuf.PrintEnd := PrintEnd ;
        MemBuf.Field := (FieldByName('Notes') as TMemoField);
        MemBuf.NoCRLF := False;
            for I := 1 to 5 do
              begin
                dbstring := AReport.GetMemoLine(MemBuf, isEOL);
                if dbstring <> '' then
                  begin
                    YPos := YPos + 0.15;
                    AReport.GoToXY(PrintEnd,YPos);
                    AReport.PrintLn(dbstring);  // PrintTab
                  end;
              end;
            YPos := YPos + 0.2;


    MemBuf.Free;
    end;
end;

Open in new window

ee-rave-report2.jpg
0
 
jimyXCommented:
You may consider using the method that's used in this demo:
http://www.nevrona.com/files/rpfish.zip
0
 
jimyXCommented:
The basic lines are:
uses RpDBUtil, RPBase;
...
var
  Memobuf : TDBMemobuf;
  Lines : Integer;
begin
  With Sender as TBaseReport do begin
    Memobuf := TDBMemobuf.Create;
    try
      Memobuf.PrintStart := TabStart(3);
      Memobuf.PrintEnd := TabEnd(3);
      Repeat
        Memobuf.Field := Table1Notes; // Table1Notes is the name of the field "Notes" in the TTable

        Lines := MemoLines(Memobuf);
        If Lines < 8 then begin
          Lines := 8;
        end;
        If Lines > LinesLeft then begin
          Break;
        end;

        PrintMemo(Memobuf,Lines,true);

        Table1.Next;
      until Table1.EOF;
    finally
      Memobuf.Free;
    end;
  end;

Open in new window

0
 
BdLmAuthor Commented:
Memobuf.Field := Table1Notes; // Table1Notes is the name of the field "Notes" in the TTable
  is not working in my code , my second try also fails .....
procedure TForm1.RavePrintDBmemo2 ( PrintStart, PrintEnd : Real; YPos : Real ; AReport : TBasereport ) ;

var  Memobuf : TDBMemobuf;
     Lines : Integer;
begin
  With AReport do begin

    try
     Memobuf := TDBMemobuf.Create;

     Memobuf.PrintStart := TabStart(3);

     Memobuf.PrintEnd := TabEnd(3);

     Memobuf.Field := ReportTable.FieldByName('Notes'); // error field and Tmemofield not same datatype .... 

     Lines := MemoLines(Memobuf);

     If Lines < 8 then
         begin
          Lines := 8;
         end;
     If Lines > LinesLeft then
         begin
          Break;
         end;

     PrintMemo(Memobuf,Lines,true);



     finally
      Memobuf.Free;
     end;
  end;

Open in new window

0
 
BdLmAuthor Commented:


----------  and this solution returns chinese memo box again ----------------------------

procedure TForm1.RavePrintDBmemo2 ( PrintStart, PrintEnd : Real; YPos : Real ; AReport : TBasereport ) ;

var  Memobuf : TDBMemobuf;
     Lines : Integer;
begin
  With AReport do begin

    try
     Memobuf := TDBMemobuf.Create;

     Memobuf.PrintStart := TabStart(3);

     Memobuf.PrintEnd := TabEnd(3);

     Memobuf.Field := TMemoField(ReportTable.FieldByName('Notes')); // Table1Notes is the name of the field "Notes" in the TTable

     Lines := MemoLines(Memobuf);

     If Lines < 8 then
         begin
          Lines := 8;
         end;

     PrintMemo(Memobuf,Lines,true);


     finally
      Memobuf.Free;
     end;
  end;
end;
0
 
BdLmAuthor Commented:
fine, the chines char issue is now gone
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.