Solved

rave reports , print memo field

Posted on 2011-03-15
10
3,456 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
Comment Utility
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
Comment Utility
dbstring := GetMemoLine(MemBuf,XEOL);

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

Expert Comment

by:jimyX
Comment Utility
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
 
LVL 8

Author Comment

by:BdLm
Comment Utility
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
Comment Utility
You may consider using the method that's used in this demo:
http://www.nevrona.com/files/rpfish.zip
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 24

Expert Comment

by:jimyX
Comment Utility
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
Comment Utility
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
Comment Utility


----------  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
Comment Utility
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
Comment Utility
fine, the chines char issue is now gone
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now