0% found this document useful (0 votes)
36 views11 pages

Introduction To Rave Reports

This document serves as an introduction to Rave Reports, specifically focusing on Code Based reports in Delphi 7. It explains the process of creating reports using Delphi code, including examples of simple, tabular, and graphical reports. The document also highlights the flexibility of Code Based reporting compared to the Visual Designer, which will be covered in Part II.

Uploaded by

belghit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views11 pages

Introduction To Rave Reports

This document serves as an introduction to Rave Reports, specifically focusing on Code Based reports in Delphi 7. It explains the process of creating reports using Delphi code, including examples of simple, tabular, and graphical reports. The document also highlights the flexibility of Code Based reporting compared to the Visual Designer, which will be covered in Part II.

Uploaded by

belghit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Introduction to Rave Reports - Part I: Code Based

Reports
By: Leonel Togniolli

Abstract: This is a introduction to Rave Reports. Part I describes how to work with Code Base reports. - by Leonel
Togniolli

Introduction to Rave Reports - Part I: Code Based


Reports
Delphi 7 has included Rave Reports as the default reporting solution, replacing Quick Reports. Since they work in
very different paradigms, many people were confused by the new environment. This is intended as an
introduction for people who haven't worked with Rave yet, and would like to start.

Delphi 7 ships with Rave Reports 5.0.8. If you haven't already, download the update from the registered users
page, since it fixes some important problems.

You can develop reports with Rave using two different ways: Code Based or with the Visual Designer. This
document describes how to work with the code based engine. Part II will describe the Visual Designer.

Code Based Reports


With Code Based, you write reports using plain Delphi code. That provides a very flexible way displaying any kind
of data, allowing any kind of complex layouts.

To write a code based report, just drop a TRvSystem component on the form and write the report on the OnPrint
event handler. Sender is the report you are creating, and can be typecasted to TBaseReport. It contains all the
methods you need to output information to that particular report.

Simple Code Base Report


Here's a simple report using the code based mechanism:

procedure TFormMain.RvSystemPrint(Sender: TObject);


begin
with Sender as TBaseReport do
begin
SetFont('Arial', 15);
GotoXY(1,1);
Print('Welcome to Code Based Reporting in Rave');
end;
end;

To execute this report, call RvSystem.Execute method.

So, what does that simple code do? First, it calls SetFont to select the font and size of the text that will be printed
from that point on. Then it positions the cursor on the coordinates (1,1). These coordinates are expressed using
the units set in the SystemPrinter.Units property of the RvSystem object, and it defaults to Inches. You can set it
to unUser and set a number relative to Inches in the SystemPrinter.UnitsFactor property. For example, if
UnitsFactor was set to 0.5 then 1 unit would correspond to half an inch. Finally, the code calls the Print method to
output the text. Here's the output:
Tabular Code Based Report
Here's another example. It displays a list of the folders in the root of the current drive, along with a recursive count
of number of files and folder, and total size of the files included in each folder.

procedure TFormMain.PrintTabularReport(Report: TBaseReport);


var
FolderList : TStringList;
i : Integer;
NumFiles : Cardinal;
NumFolders : Cardinal;
SizeFiles : Cardinal;
Root : string;
begin
with Report do
begin
SetFont('Arial', 15);
NewLine;
PrintCenter('List of Folders in the Drive Root', 4);
NewLine;
NewLine;
ClearTabs;
SetTab(0.2, pjLeft, 1.7, 0, 0, 0);
SetTab(1.7, pjRight, 3.1, 0, 0, 0);
SetTab(3.1, pjRight, 3.5, 0, 0, 0);
SetTab(3.5, pjRight, 4.5, 0, 0, 0);
SetFont('Arial', 10);
Bold := True;
PrintTab('Folder Name');
PrintTab('Number of Files');
PrintTab('Number of Folders');
PrintTab('Size of Files');
Bold := False;
NewLine;
FolderList := TStringList.Create;
try
Root := IncludeTrailingPathDelimiter(ExtractFileDrive(ParamStr(0)));
EnumFolders(FolderList, Root);
for i := 0 to FolderList.Count - 1 do
begin
PrintTab(FolderList[i]);
GetFolderInfo(IncludeTrailingPathDelimiter(Root+FolderList[i]),
NumFiles, NumFolders, SizeFiles);
PrintTab(Format('%u',[NumFiles]));
PrintTab(Format('%u',[NumFolders]));
PrintTab(Format('%u bytes',[SizeFiles]));
NewLine;
end;
finally
FolderList.Free;
end;
end;
end;

Notice that a different approach has been taken: instead of specifying the coordinates of each text output, the
printing was done using Lines and Columns as references. The line heigh depends on the size of the current font:
each unit represents 1/72nds of an inch, so each line printed with a size 10 font will have, aproximatelly, a height
of 0.138 inches. Lines are advanced after calls to PrintLn or NewLine. Colums are defined using calls to the
SetTabs method, and the PrintTab method will print the text in the current column and advance to the next one.
Here's the output:

You can find the full source, including the implementation of EnumFolders and GetFolderInfo, on CodeCentral.

Graphical Code Based Report


You can include shapes and images in your code based report, along with the text. The following example
demonstrates that:

procedure TFormMain.PrintGraphicsReport(Report: TBaseReport);


var
Bitmap : TBitmap;
begin
with Report do
begin
Canvas.Brush.Color := clGray;
Rectangle(0.3, 0.3, 4.7, 3.3);
SetFont('Arial', 15);
FontColor := clRed;
PrintXY(0.5,0.5, 'Just look at all the graphics!');
Bitmap := TBitmap.Create;
try
Bitmap.LoadFromFile('delphi.bmp');
PrintBitmap(3.5,0.3,1,1, Bitmap);
PrintBitmap(1,2,3,3, Bitmap);
Canvas.Pen.Color := clBlue;
Canvas.Brush.Bitmap := Bitmap;
Ellipse(5,0.3,6,3.3);
Ellipse(2,1,4,1.9);
finally
Bitmap.Free;
end;
Canvas.Pen.Color := clBlack;
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := clYellow;
Pie(0.7,0.7,1.7,1.7,1,1,1,2);
Canvas.Brush.Color := clGreen;
Pie(0.7,0.7,1.7,1.7,1,2,1,1);
end;
end;

In this example the methods Rectangle, Ellipse and Pie have been used draw shapes with different fills. Bitmaps
were outputted using PrintBitmap and as the brush of the ellipses. Here's the output:

A sample application, containing full source code for those three examples can be found at CodeCentral.
procedure TForm1.ImprimerClick(Sender: TObject);
begin
RvProject1.Open; // <<<<<<<<<<<<<<<<<<<<<<<<<<<< ici
RvProject1.ExecuteReport('Etiquettes');
RvProject1.Close;
end;

procedure TForm1.RvProject1AfterOpen(Sender: TObject);


var MyPage : TRavePage;
Ravebitmap : TRaveBitMap;
ImageJPEG : TJpegImage;
begin
MyPage := RvProject1.ProjMan.FindRaveComponent('Etiquettes.Page1',nil) AS
TRavePage;
RaveBitMap := RvProject1.ProjMan.FindRaveComponent('BitMap1',MyPage) AS
TRaveBitMap;
IF FileExists(Ilogo.text) then
begin
ImageJPEG := TJPEGImage.CREATE; // CREATE a TJPEGImage class
try
ImageJPEG.LoadFromFile(ILogo.text); // LOAD up JPEG ImageJPEG FROM
ImageStream
ImageJPEG.DIBNeeded; // Conversion JPEG vers
Bitmap
RaveBitMap.Image.Assign(ImageJPEG);
finally
ImageJPEG.Free;
end;
end
else RaveBitmap.Image:=nil;

end;
[jpg][D2006][Rave 6.5] mettre une image JPG
dans rave

Comment mettre une image jpg dans un


état rave

Je remets mes gants de boxe

premièrement avec des images fixes , j'ai


utilisé le composant (ND_JPEG) fourni par
Nevrona et là pas de soucis majeur

maintenant quid avec des images (nom de


l'image dans le fichier) changeant pour
chaque enregistrement (ou presque) .
Jusqu'a présent pour des BMP je traitait le
chargement de l'image via rave

Code Event Editor :

FUNCTION
bitmap1_onbeforePrint(self :
TRaveBitmap);
begin
IF (DataMemoryNOMIMAGE.isnull) then
self.visible:=false;
else
self.visible:=true;
self.filelink:=DataMemoryNOMIMAGE.as
String;
end IF;
end OnBeforePrint;

bon d'accord , c'est peut-être pas la


meilleure solution , mais la seule que j'ai
trouvé

Je comptais faire la même chose avec une


image JPG mais helas
rave me rembarre en me disant que
FileLink est inconnu . Quelle solution me
reste t-il ?

j'ai bien regardé les deux posts du forum


concernant les jpg mais j'y perd mon latin .

Comment puis-je
a) modifier le composant de rave pour
faire de filelink une propriété reconnue
ou
b) faire pour que delphi envoie l'image (là
j'ai carrément besoin d'une bouée)

00

07/05/2008, 11h30 #2

chtiot je le fais avec des bitmaps dans


l'événement onValidateRow :
Membre éclairé
Code :

// C'est un bitmap
variable //
if fileExists(BdPath
+ 'Images\' + xText + '.bmp')
then begin

(rvPage.Components[ncmp] as
TRaveBitMap).Image.LoadFromFile
(BdPath + 'Images\' + xText +
'.bmp');
Inscription: octobre 2002
end
Messages: 379
else begin

Points: 356 (rvPage.Components[ncmp] as


TRaveBitMap).Image := nil;
end;
end;
Je ne sais pas si on peut le faire avec
un jpeg...

00

07/05/2008, 14h26 #3

SergioMaster j'avais déjà lu ton post à ce sujet mais ce que je ne comprends


pas c'est
Modérateur
où tu pêches (rvPage.Components[ncmp] as TRaveBitMap)

le TRaveBitmap est dans quelle unité ?

tu browse tout les composants Rave pour récupérer le bon ?

j'entrevois bien une solution , avec quelque chose du genre

Code :
// uses JPEG ajouté
Nom : Serge Girard
procedure TForm1.RvDataSetConnection2ValidateRow(
Inscription: janvier 2007 Connection: TRvCustomConnection; var ValidRow:
BOOLEAN);
Localisation: Nantes - Ile var
d'Yeu Image: TJPEGImage;
begin
Âge: 54
IF pos('.JPG','PONTON.JPG')>0 then begin // ici
Messages: 2 904
ce n'est qu'un test bidon
Image := TJPEGImage.CREATE; // CREATE a
Points: 3 374 TJPEGImage class
try
Image.LoadFromStream('C:\Temp\ponton.jpg'); //
LOAD up JPEG image FROM ImageStream
Image.DIBNeeded; // Convert JPEG TO bitmap
format
Bitmap.Assign(Image);
finally
Image.Free;
end;
end; { IF }
end;

mais du coup c'est Bitmap que je ne sais pas bien assigné.


Une Idée ?

j'etudie également la solution dans les evenements onGetRow


et on getCol mais j'ai pas fait latin et le peu que j'ai je le perds

00

07/05/2008, 14h54 #4

chtiot il me semble que c'est dans rvCsStd.

Membre éclairé
il te suffit de mettre un composant Bitmap (onglet Standard
dans le concepteur Rave) sur ton état Rave ou de le créer en
dynamique avec createChild

Inscription: octobre 2002

Messages: 379

Points: 356
00

08/05/2008, 09h06 #5

SergioMaster Voilà à quoi je suis arrivé :

Modérateur Code :

procedure TForm1.RvDataSetConnection2ValidateRow(
Connection: TRvCustomConnection; var ValidRow:
BOOLEAN);
var
MyPage : TRavePage;
Ravebitmap : TRaveBitMap;
ImageJPEG : TJpegImage;
begin

MyPage :=
RvProject1.ProjMan.FindRaveComponent('Report2.MainPage',
nil) AS TRavePage;
RaveBitMap :=
Nom : Serge Girard RvProject1.ProjMan.FindRaveComponent('BitMap1',MyPage)
AS TRaveBitMap;
Inscription: janvier 2007 IF assigned(RaveBitMap) then
begin
Localisation: Nantes - Ile
ImageJPEG := TJPEGImage.CREATE; // CREATE a
d'Yeu
TJPEGImage class
Âge: 54 try
ImageJPEG.LoadFromFile('C:\Temp\ponton.jpg'); //
Messages: 2 904 LOAD up JPEG ImageJPEG FROM ImageStream
ImageJPEG.DIBNeeded; // Convert JPEG TO bitmap
Points: 3 374 format
RaveBitMap.Image.Assign(ImageJPEG);
finally
ImageJPEG.Free;
end;
end; { IF }
end;

le plus est que je n'ai pas besoin de ND_JPEG de Nevrona puisque


c'est une RaveImage qui récupére mon JPEG ce qui était mon but
puisque j'ai des images BMP ou JPEG dépendant des articles . Il ne
me reste plus maintenant qu'a mettre cela en forme dépendant
des données , tester le format,l'existance etc.. et le tour sera joué

Maintenant , faut-il mieux le faire dans le


ValidateRow,GetRow,GetCols ....
les prochains tests me le diront

je laisse ouvert pour le plaisir de la discussion


00

08/05/2008, 10h06 #6

SergioMaster Finalisation ?

Modérateur

résultat de mes cogitations

les puristes voudront peut-être utiliser des streams


il y'a peut être moyen de connaitre le type d'image sans passer
par l'extension ?
on peut certainement enjoliver le code pour les différentes
extensions (mais dans mon cas les JPG sont bien des jpeg les BMP
des BMP)

le principe doit pouvoir s'appliquer aux GIF et PNG à voir


Nom : Serge Girard
PS : il faut déclarer rvCsStd et rvClass dans la liste des uses
Inscription: janvier 2007
Code :
Localisation: Nantes - Ile
d'Yeu procedure TForm1.RvDataSetConnection1ValidateRow(
Connection: TRvCustomConnection; var ValidRow:
Âge: 54 BOOLEAN);
var
Messages: 2 904
MyPage : TRavePage;
Points: 3 374
Ravebitmap : TRaveBitMap;
ImageJPEG : TJpegImage;
NomImage,extension : String;
jpeg : BOOLEAN;
begin
MyPage :=
RvProject1.ProjMan.FindRaveComponent('Report2.MainPage',
nil) AS TRavePage;
RaveBitMap :=
RvProject1.ProjMan.FindRaveComponent('BitMap1',MyPage)
AS TRaveBitMap;
NomImage:=Uppercase(Table1.FIELDS[0].asString);
Extension:=ExtractFileExt(NomImage);
jpeg:=(trim(Extension)='.JPG');
IF FileExists(NomImage) then
begin
IF assigned(RaveBitMap) AND Jpeg then
begin
ImageJPEG := TJPEGImage.CREATE; // CREATE a
TJPEGImage class
try
ImageJPEG.LoadFromFile(NomImage); // LOAD up
JPEG ImageJPEG FROM ImageStream

ImageJPEG.DIBNeeded; //
Conversion JPEG vers Bitmap
RaveBitMap.Image.Assign(ImageJPEG);
finally
ImageJPEG.Free;
end;
end
else begin
RaveBitmap.Image.LoadFromFile(NomImage);
end; { IF }
end
else RaveBitmap.Image:=nil;
end;

J' hésite à mettre résolu , pour que l'on puisse me faire des
remarques et suggestions

You might also like