将图元文件传递给fastreport masterdata图像控件

问题描述 投票:0回答:1

我需要将图形(元文件)传递给每个打印记录的主数据带上的image1控件。不幸的是,我无法在onbeforeprint事件中使用Loadfromfile方法,因为图元文件是另一个文件的一部分,因此我必须先提取它,然后将其传递给masterdata的控件。我尝试使用用户函数声明选项,但它们使用Variant类型,因此,我无法分配图元文件。我是FR的新手。还有另一种方法可以完成这项工作吗?在此先感谢。

delphi fastreport
1个回答
0
投票

定义一个用户函数,该函数接受图片对象的名称以及您需要从报告中获取的任何其他参数。

frxReport1.AddFunction(
  'procedure MyTest(const APicViewName : string)',
  'CustomFunctions',
  'This is the description of the Test function'
);

定义功能:

procedure TForm1.MyTest(const APicViewName : string);
var
  Pic : TfrxPictureView;
  Stream : TStream;
begin
  Pic := TfrxPictureView(TmpCurReport.FindObject(APicViewName));
  if(not Assigned(Pic)) or (not Pic.ClassType.InheritsFrom(TfrxPictureView)) then
    Exit;



  Stream := <TMemoryStream/TFileStream/...>.Create;
  try
    //load and process your image as you need and load it into the Stream
    //...

    Stream.Position := 0;
    Pic.LoadPictureFromStream(Stream);
  finally
    Stream.Free;
  end;

end;

frxReport1.OnUserFunction事件处理程序中:

function TForm1.frxReport1UserFunction(const MethodName: string; var Params: Variant): Variant;
begin
  if(MethodName = 'MYTEST')
  then Test(Params[0]);
end;
© www.soinside.com 2019 - 2024. All rights reserved.