quick report的套打问题(50分)

  • 主题发起人 主题发起人 lps
  • 开始时间 开始时间
L

lps

Unregistered / Unconfirmed
GUEST, unregistred user!
维护一个程序,用的D7+Qreport 4.06,要套打,不太熟悉QR。现在的想法是能否把格式保存成一个文件,类似于fastreport的frf和fr3这样的,便于调整位置,调整工作肯定不是经常做的(最终用户不能做此事),如何实现不重新编译,只修改报表?
现在找到一些文档(附后),是QR3的,说不能传参数,QR4呢?如何实现?
PS:我的报表的数据是来自程序中的一些变量
Q. I want to be able to execute a report made in "QREditor"
(*.qr) without using the QREditor. How can Ido
this so the user can not edit the report?
A. You can load a qreditor report with the QRLoadREport function (defined in the qrextra unit). Remember to add the qrextra unit to your uses clause. The following code shows how load, preview, and finally free a saved report:
procedure TfrmTest.btnQRLoadReportClick(Sender: TObject);
var
MyReport: TQuickRep;
begin
try
MyReport := QRLoadReport('myreport.qr');
MyReport.Preview;
finally
QRFreeReport(MyReport);
end;
end;
For QuickReport 3.0.5 (or later) you would use a TQREditor object to load the report.
Example:
with TQREditor.Create(self)do
begin
OpenReportFile('myreport.qr');
PreviewReport;
Free;
end;
------------------
Q. How can I send parameters to the QREditor when using a Query?
A. This is not directly supported in the current release. What you cando
is to load the saved report and modify the query properties. While you can't pass parameters, you can build an SQL statement with those parameters embedded in the text of the SQL statement. The following example loads a previously saved report and replaces the SQL property if a TQuery was being used or it sets the filter if a TTable is being used:
QuickReport 2:
procedure TfrmMain.Button1Click(Sender: TObject);
var
MyEdit: TfrmQREdit;
begin
MyEdit := TfrmQREdit.Create(Application);
with MyEditdo
begin
show;
qreditor1.OpenReportFile('cust1563.qr');
if qreditor1.Report.DataSet is TQuery then
begin
with TQuery(qreditor1.Report.DataSet)do
begin
SQL.Clear;
SQL.Add('select * from customer where CustNo=6312');
Open;
end;
end
else
begin
with TTable(qreditor1.Report.DataSet)do
begin
Active := False;
{$ifdef win32}
Filter := 'CustNo=6312';
{$endif}
Active := True;
end;
end;
qreditor1.Report.Preview;
Close;
{ if you want to make the editor go away after the preview }
end;
end;

QuickReport 3.0.5: (from the QREditor demo on ourdo
wnload page)
procedure TEdtDemoFrm.btnSalesPreviewClick(Sender: TObject);
var
EmployeeNumber: integer;
MyReport: TQuickRep;
begin
// Prompt the user for an employee number to report on
if GetEmployeeNumber(EmployeeNumber) then
begin
with TEdtFrm.Create(Application)do
begin
try
QREditor1.ShowMenu := true;
QREditor1.OpenReportFile('sales.qr');
// Get the report variable
MyReport := TQuickRep(QREditor1.ReportEditor.FormEditor.MainControl);
// Now update the query
if MyReport.DataSet is TQuery then
begin
with TQuery(MyReport.DataSet)do
begin
if Active then
Close;
// Set the SQL statement. If the user accidently changes the SQL
// statement, this will make sure that the correct one is in place
SQL.Text := 'SELECT OrderNo, CustNo, SaleDate, EmpNo, ItemsTotal, LastName, FirstName '+
'FROM orders JOIN employee ON orders.empno = employee.empno '+
'WHERE employee.empno = :p0 '+
'ORDER BY orders.empno, SaleDate';
// Pass the selected employee number as the parameter to this report
Params[0].AsInteger := EmployeeNumber;
// open the query again
Open;
end;
end;
// Display the report
QREditor1.PreviewReport;
finally
Free;
end;
end;
end;
end;
------------------
 

Similar threads

I
回复
0
查看
3K
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
1K
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部