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

Passing metafile to fastreport masterdata image control

我需要将图形(图元文件)传递给每个打印记录的主数据带上的 image1 控件。

不幸的是,我不能在OnBeforePrint事件中使用LoadFromFile方法,因为图元文件是另一个文件的一部分,我必须先提取它,然后将它传递给masterdata的控制。

我尝试使用用户函数声明选项,但他们使用 Variant 类型,因此,我无法分配图元文件。

还有其他方法吗?

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

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

定义函数:

procedure TForm1.MyTest(const APicViewName : string);
var
  Pic : TfrxPictureView;
  Stream : TStream;
begin
  Pic := TfrxPictureView(frxReport1.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 MyTest(Params[0]);
end;