繁体   English   中英

Delphi,FastReport参数

[英]Delphi, FastReport params

我有打印问题

procedure Sendparams(const Pparams,pparvalues :array of string);
begin
              for I := 0 to Length(Pparams) - 1 do
              begin
               lpar_name:=Pparams[i];
               lpar_val:=pparvalues[i] ;
               FfrxReport.Variables.AddVariable('Bez', lpar_name, lpar_val);
end;

Sendparams(['buyer','delivery'], ['buyer address', 'delivery address']);

一切正常,直到我尝试打印报告。 它说:期望在Memo2上表达。

Memo1.memo = '[buyer]';
Memo2.memo = '[delivery]';

memo1和memo2所有其他属性都相同。 有什么建议么?

有不同的可能陷阱。

  1. 如果要使用Addvariable (而不是variables.add )类别,则必须在报告中定义Bez ,否则将不会添加变量。 **
  2. 报告中变量的分配必须看起来像Memo1.Lines.Text :=<buyer>;
  3. 您将必须引用变量的字符串值
    Sendparams(['buyer','delivery'], [QuotedStr('buyer address'), QuotedStr('delivery address')]);

** 在此处输入图片说明

另一个尝试可能是这样的,避免字符串的开放数组(名称和值的计数可能偶然地不同),避免在Sendparams硬引用该报表,并处理已经在报表中定义的变量。

Function PrepareReport(Report:TfrxReport; Variables: TfrxVariables;
                       ReportName: String):Boolean;// -- other parameters
var
 i,k:Integer;
begin
   // ....... other initializations

    if Assigned(Variables) then
      for i := 0 to Variables.Count - 1 do
      begin
        k := Report.Variables.IndexOf(Variables.Items[i].Name);
        if k > -1 then
          Report.Variables.Items[k].Value := Variables.Items[i].Value
        else
        begin
          with Report.Variables.Add do
          begin
            Name := Variables.Items[i].Name;
            Value := Variables.Items[i].Value;
          end;
        end;
      end;
end;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM