var
ltemp : TfrxVariable;
begin
ltemp := frxReport1.Variables.Add;
ltemp.Name := ' TESTVAR' ;
frxReport1.Variables.AddVariable('TESTVAR','測試','12');
frxReport1.Variables.AddVariable('TESTVAR','測試23','qwewr');
frxReport1.DesignReport();
end;
運行後,在報表上增加一個變量[測試23]
然後點擊“預覽”,報錯:
網上查詢都是修改這個組件的源碼如下:
frxClass單元中
function TfrxReport.DoGetValue(const Expr: String; var Value: Variant): Boolean;
裏面的源語句 if Pos(#13#10, val) <> 0 then 修改後的語句 if (Pos(#13#10, val) <> 0 ) or( ds=nil) then
但FastReport爲收費組件,此類常用就出現的報錯,不應通過修改組件源碼解決,應該是自身使用組件不當造成的;參照網上解決方案,將自身代碼改成
procedure TForm1.Button1Click(Sender: TObject);
var
ltemp : TfrxVariable;
begin
ltemp := frxReport1.Variables.Add;
ltemp.Name := ' TESTVAR' ;
frxReport1.Variables.AddVariable('TESTVAR','測試','12');
frxReport1.Variables.AddVariable('TESTVAR','測試23','qwewr'#13#10);
frxReport1.DesignReport();
end;
再運行就不報錯了