在 Delphi 7 中,我有一份用 QuickReport 编写的报告。
报告由另一种形式的函数调用
var RepResult : integer
RepResult := ShowReport(param1,param2...);
报告内的功能如下
` var QuickRep1 : TQuickReport;
ReportResult : integer;
function ShowReport(param1,param2...) : integer
begin
...
QuickRep1.PreviewModal;
Result := ReportResult;
end;`
变量ReportResult的计算比较复杂,基于QuickReport内部的很多查询,在DetailBands、ChildBands、LoopBands等事件中进行计算。 报告和计算工作正常,但现在客户希望在另一个地方查看此计算的结果而不查看报告。 所以问题是:是否可以只获取函数的结果而不预览或打印报告?
我尝试了 QuickRep1.PreviewModeless 和 fastrep1.print 到不存在的打印机。没有任何效果
将您的函数公开,以便您可以在代码中的任何位置调用它。之后,您需要创建一个公共布尔值来告诉您是否显示报告。它可能看起来像这样:
var
shouldShowReport : boolean = false;
然后你需要做的是稍微改变一下你的函数,添加一个布尔值作为参数,如下所示:
function ShowReport(param1,param2...; showReport : boolean) : integer
然后您需要根据传递的布尔值更改逻辑,以便您可以像现在一样显示报告,或者只返回一个没有预览模型的整数。这是一个例子:
function ShowReport(param1,param2...; showReport : boolean) : integer
begin
//If you need to show the report then you call the PreviewModal
if showReport then begin
...
QuickRep1.PreviewModal;
end;
//Then you get the result anyway
Result := ReportResult;
end;
之后,您需要弄清楚要在哪里调用该函数,并根据是否需要在该逻辑中显示报告来更改 shouldShowReport 的值。然后在调用函数时将布尔值作为参数传递给函数:
//If this is the part where the customer doesn't want to see the whole report
shouldShowReport := false;
RepResult := ShowReport(param1,param2..., shouldShowReport);
//repResult is an integer like you've shown already
最后你需要以某种方式显示结果。我不知道你打算如何做到这一点,但最简单的方法是使用标签。您可以从组件中获取它并将其放在表单上。之后,您可以根据需要对属性进行一些更改。然后您需要将结果赋予标签标题属性。不要忘记您的结果是一个整数,如果您直接将整数传递给标题,则会收到错误。这就是为什么您需要首先将其设为字符串。对于这个例子,我假设您将标签命名为 lblResult
lblResult.Caption := IntToStr(RepResult);