Delphi form

This example shows how to insert an image from Delphi form into the report.

We will use graphic of TImage component on the form.  To insert graphic in the report there is a function DrawMemoryBitmap, defined in EkUDFList1 component. EkUDFList1 is linked to EkRtf1 report component. The report template is saved in EK_RTF_InMemoryBitmap.rtf file.

 

Note that property ResultType of user function DrawMemoryBitmap is set to udfrTPicture. It means that the type of UDFResult object in function OnCalculate event handler is TPicture.

 

Image on the form

 

Report template

The report template contains only the function call.

Code of function DrawMemoryBitmap

procedure TForm1.EkUDFList1Functions0Calculate(Sender: TObject;
Args: TEkUDFArgs; ArgCount: Integer; UDFResult: TObject);
begin
(* EK RTF User Defined Function DrawMemoryBitmap *)
With UDFResult as TPicture do
begin
Bitmap.Width := Image1.Width;
Bitmap.Height := Image1.Height;
Bitmap.Canvas.Draw(0,0,Image1.Picture.Graphic);
end;
end;

Code to generate the report

procedure TForm1.Button1Click(Sender: TObject);
begin
(* check report template file *)
if not FileExists(EkRTF1.InFile) then
begin
if RTFDialog.Execute then
begin
EkRTF1.InFile := RTFDialog.FileName;
end else exit;
end;
  (* create report *)
  EkRtf1.OutFile := 'EK_RTF_InMemoryBitmap_'+IntToStr(Random(10000))+'.doc';
  EkRtf1.ExecuteOpen([],SW_SHOW);
end;


Result