Problems loading a report correctly.
I am having problems getting the report to load into memory. Below is the
snippet of the code. Initially I got an out of bounds error on the line
"AutoSearchFields[0]...etc". In the report I did have an auto search field.
I tried some investigation by commenting out the AutoSearchFields line and
removing it from the report. The report file WOQReport.pdf was generated but
was completely blank. I concluded that there was some problem with the
report loading into memory on the line "reWorkOrder.LoadReport...etc". Hence
Delphi not finding the AutoSearchFields array when it gets to that line.
Any ideas?
I am using ReportBuilder Enterprise Edition Version 6.03 with Borland Delphi
Version 7.0 (Build 4.453).
Regards, Lau
reWorkOrder := TppReportExplorer.Create(nil);
rptWorkOrder := TppReport.Create(nil);
try
with rptWorkOrder do
begin
reWorkOrder.LoadReport('Work Order Quick Report', 41);
AutoSearchFields[0].SearchExpression :=
IntToStr(TTemplate_TreeView(FTemplate_TreeView).Selected.Item_ID);
ShowAutoSearchDialog := false;
AllowPrintToFile := true;
DeviceType := 'PDFFile';
TextFileName := 'C:\WINDOWS\Temp\WOQReport.pdf';
ShowPrintDialog := false;
ShowAutoSearchDialog := false;
Print;
end;
finally
reWorkOrder.Free;
rptWorkOrder.Free;
end;
This discussion has been closed.
Comments
1. I recommend making the form/datamodule the Owner of the Report and
ReportExplorer
reWorkOrder := TppReportExplorer.Create(Self);
rptWorkOrder := TppReport.Create(Self);
2. The ReportExplorer requires the Designer, which in turn requires the
Report. This is shown in the RBuilder\Demos\EndUser\ReportExplorer example
and in the Developers Guide tutorials.
Report <--- Designer <--- ReportExplorer
3. Below is an article about loading reports stored by the report explorer.
There are two approaches - one of which you are using now.
4. After loading the report, check whether Report.AutoSearchFieldCount is
greater than 0..
if Report.AutoSearchFieldCount > 0 then
begin
AutoSearchFields[0].SearchExpression
end;
---------------------------------------------------------------
Tech Tip: How to Programmatically Load Reports that were Saved
using the Report Explorer
---------------------------------------------------------------
1. The ReportExplorer has a run-time interface you can use to load reports
using the ReportExplorer.LoadReport method. You can use this method without
actually 'showing' the report explorer form. (See the online help topic for
TppReportExplorer.)
2. If you want use Report.Template.LoadFromDatabase, RB will locate the
report stored in the database table based upon the NameField value only.
However, for the rb_item table you need Folder_Id, Name to locate a record
uniquely.
To override this default behavior, assign an event-handler to the
Report.Template.OnLocateRecord event.
example:
TmyForm = class(TForm)
private
function ReportLocateRecordEvent(Sender: TObject; const aReportName:
String): Boolean;
end;
procedure TmyForm.FormCreate(Sender, TObject);
begin
{assign the event handler}
FReport.Template.OnLocateRecord := ReportLocateRecordEvent;
end;
function TmyForm.ReportLocateRecordEvent(Sender: TObject; const aReportName:
String): Boolean;
begin
{add logic here to locate the record and return True if it is found}
Result := myLocateReportFunction(FFolderid, aReportname);
end;
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Managed to get it working.
Thanks.