Solved

rave reports , print memo field

Posted on 2011-03-15
10
3,548 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:BdLm
  • 5
  • 5
10 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 35139344
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
 
LVL 8

Author Comment

by:BdLm
ID: 35141560
dbstring := GetMemoLine(MemBuf,XEOL);

this line of code I can't understand
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35141699
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 8

Author Comment

by:BdLm
ID: 35141776
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
 
LVL 24

Expert Comment

by:jimyX
ID: 35142165
You may consider using the method that's used in this demo:
http://www.nevrona.com/files/rpfish.zip
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35142234
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
 
LVL 8

Author Comment

by:BdLm
ID: 35148014
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
 
LVL 8

Author Comment

by:BdLm
ID: 35148138


----------  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
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 35148858
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
 
LVL 8

Author Comment

by:BdLm
ID: 35150149
fine, the chines char issue is now gone
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question