質問

I have a problem with printing

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']);

Everything works fine until I try to print report; it says: Expression expected on Memo2.

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

memo1 and memo2 all other properties are the same. Any suggestions?

役に立ちましたか?

解決

There are different possible traps.

  1. If you want to use Addvariable (instead of variables.add) the category, in your case Bez has to be defined in the report, otherwise the variables won't be add. **
  2. The assignment of the variables within the report hast to look like Memo1.Lines.Text :=<buyer>;
  3. You will have to quote the string values of the variables
    Sendparams(['buyer','delivery'], [QuotedStr('buyer address'), QuotedStr('delivery address')]);

**enter image description here

Another attempt could be something like this, to avoid open arrays of string (where count of names and values accidentally could differ), to avoid a hard reference to the report within Sendparams and to deal with variables which already could be defined within the report.

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帰属
所属していません StackOverflow
scroll top