Question
“How do I programmatically load reports that were savedĀ using the Report Explorer ?”
Solution
- 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.)
- 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.
Sample Delphi code:
TmyForm = class(TForm)
private
function ReportLocateRecordEvent(Sender: TObject; const aReportName: String): Boolean;
function myLocateReportFunction(aFolderID: Integer; aReportName: String): Boolean;
end;
uses
ppTypes, ppRptExpCommon;
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
Result := myLocateReportFunction(FFolderid, aReportname);
end;
function TmyForm.myLocateReportFunction(aFolderID: Integer; aReportName: String): Boolean;
var
lsFieldNames: String;
begin
lsFieldNames := ReportExplorer.ItemFieldNames.FolderId + ';' +
ReportExplorer.ItemFieldNames.ItemType + ';' +
ReportExplorer.ItemFieldNames.Name;
Result := ReportExplorer.ItemPipeline.Locate(lsFieldNames,
VarArrayOf([aFolderID, itReport, aReportName]),
[pploCaseInsensitive]);
end;