Passing a Bitmap from app to report

Please help!!

I have an app that needs to generate a picture for my reports and i need to pass the picture to the reports but i dont want to have to save each file to disk and reload it etc. I have tried the code below but just get an error on my report, help...
function TForm1.QRCodeStream(encData: String; x, y: Integer): TStream;
var
  tmpCanvas: tBitMap;
begin
// necessary logic
  result:= TStream.Create;
  tmpCanvas := TBitMap.Create;
  QRCode1.code := encData;
  QRCode1.paintBarcode(tmpCanvas.Canvas);

  tmpcanvas.SaveToStream(result);
  tmpcanvas.Free;

end;

function TForm1.MainReportUserFunction(const MethodName: string;
  var Params: Variant): Variant;
begin
  if MethodName = 'QRCODE' then
    Result := Integer(QRCodeStream(Params[0], Params[1], Params[1]));
end;


//this next lin is in the forms create
  MainReport.AddFunction('function QrCode(encData: String; X, Y: Integer): TStream');

Then on my report attached to some data whitch all works fine and has been tested i have a picture object and i have set the onBeforePrint For the Picture to
Picture2.LoadFromStream(QrCode('This is a tes ' + <Time>,1,1) );

I know the code is not very elegant yet but i just wanted to get it working firstly, so any advise.

Comments

  • gpigpi
    edited 2:24AM
    Use in Delphi's code
    var BMP: TBitmap;
    begin
         BMP:=TBitmap.Create;
         BMP.LoadFromFile('C:\Test.bmp');
         frxReport1.Script.Variables['pBMP']:=integer(BMP);
         frxReport1.ShowReport();
         BMP.Free;
    end;
    
    in report's script
    procedure Picture1OnBeforePrint(Sender: TfrxComponent);
    var P: TPicture;
    begin
         P:=TPicture.Create;
         P:=TPicture(pBMP);
         Picture1.Picture:=P;
    end;
    

    or use TfrxReport.OnBeforePrint event

    or use TfrxPictureView(MainReport.FindObject('Picture2')).LoadPictureFromStream function
  • edited 2:24AM
    Is your app databased? Can you insert this picture in a table (or maybe the picture is already in any table) and then use a query to get if and put on then band?

    Mick
  • edited 2:24AM
    I am new in FR. So I would like to know if the "in report's script" means to include the informed text in the property "frxReport1.ScriptText"? I don't need do anything inside the TFrxReport? I will appreciate any information related to passing a bitmap to a report. Thanks.
  • gpigpi
    edited 2:24AM
    See a demo project in attach
  • edited 2:24AM
    gpi wrote: »
    See a demo project in attach

    Thank you for the help. Unfortunatelly, I can't see the image in the report. A blank page is visualized. No image is transfered.
  • gpigpi
    edited 2:24AM
    Did you change a path to your bitmap?
    BMP.LoadFromFile('C:\Test.bmp');
    
  • edited 2:24AM
    gpi wrote: »
    Did you change a path to your bitmap?
    BMP.LoadFromFile('C:\Test.bmp');
    

    Yes, I did. In order to be sure if the image was loaded I have included in the form an Image.Bitmap. The image is correct in the form but doesn't appear in the report. Can be something related to image size?
  • gpigpi
    edited 2:24AM
    See a new test project in attach
  • edited 2:24AM
    gpi wrote: »
    See a new test project in attach

    Unfortunately, the problem remains.
  • gpigpi
    edited 2:24AM
    Unfortunately, I can't to help you. My test project works OK for me
  • edited 2:24AM
    Anyway I appreciate your willingness to want to help me.
  • edited 2:24AM
    gpi wrote: »
    Unfortunately, I can't to help you. My test project works OK for me

    Finally I found a way to solve the problem in my computer. See attached file. Thanks.
  • edited 2:24AM
    gpi wrote: »
    Use in Delphi's code
    var BMP: TBitmap;
    begin
    // <snip>
    end;
    
    in report's script
    procedure Picture1OnBeforePrint(Sender: TfrxComponent);
    // <snip>
    end;
    

    or use TfrxReport.OnBeforePrint event

    or use TfrxPictureView(MainReport.FindObject('Picture2')).LoadPictureFromStream function

    Thank you, gpi. This response was very helpful to me. >

Leave a Comment