BdLm
asked on
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
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.
ASKER
dbstring := GetMemoLine(MemBuf,XEOL);
this line of code I can't understand
this line of code I can't understand
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."
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."
ASKER
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;
ee-rave-report2.jpg
You may consider using the method that's used in this demo:
http://www.nevrona.com/files/rpfish.zip
http://www.nevrona.com/files/rpfish.zip
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;
ASKER
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 .....
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;
ASKER
---------- 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.Fie
Lines := MemoLines(Memobuf);
If Lines < 8 then
begin
Lines := 8;
end;
PrintMemo(Memobuf,Lines,tr
finally
Memobuf.Free;
end;
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
fine, the chines char issue is now gone
Open in new window
http://www.delphipages.com/forum/showthread.php?t=208806PS: The above code is not tested, you might need to adjust it to match your requirements.