Rave - General
How can I print in a report created in Rave Visual Designer a bitmap that is dynamically generated?
In Rave, there are text (DataText) and memo (DataMemo)components that allow their contents programatically set up via project parameters. The standard bitmap component doesn't have this behavior. Here are the steps we can follow to combine the power of visually designed reports and still have dynamically generated bitmaps included in the reports. In Delphi we generate a bitmap contents by using a TBitmap. As the last step we save the bitmap on disk by using TBitmap.SaveToFile. For the purpose of this demo, we save the bitmap in the same folder as the main application (Application.ExeName) and we name it 'tmp_rep.bmp'. We add a TRvProject and a TButton on our form. Change the name of the button to btnPrint. In the OnClick event write the following code:
procedure TForm1.btnPrintClick(Sender: TObject); var myBmpName: string; begin myBmpName := ExtractFilePath(Application.ExeName) + 'tmp_rep.bmp'; with RvProject1 do begin Open; try SetParam('pMyReportImage', myBmpName); ExecuteReport('Report1'); finally Close; end; end; end;
Open the Rave Designer and add a Bitmap on the Page1 of the report. Click on RaveProject (tree on the right) and then on Parameters property on the right. Add pMyReportImage as a parameter. Click on the newly added Bitmap and set it's name to MyBitmap. While the Bitmap is still selected, click on Event Editor and choose OnBeforePrint. Type in the following code: MyBitmap.FileLink := RaveProject.GetParam('pMyReportImage'); Click Compile and then Save the project. Go back to Delphi, compile and run the application. The bitmap you create dynamically in Delphi is now displayed in the report without problems.