Home End User
New Blog Posts: Merging Reports - Part 1 and Part 2

Custom Report Explorer and Save to /Load from file functionality

edited August 2005 in End User
Hi guys,

I've got RB 9, D6.
I've implemented custom Report Explorer based on the example you provided in
Demo folder.
I want to provide to user functionality of saving reports to .rtm file and
loading Report from .rtm into DB from Report Explorer bypassing loading
report into Report Designer and displaying it.
But it's not working in the way I would expect. Could you please advice if
I'm doing something wrong ?

Thanks,
Dmitry

procedure TfrmReportExplorer.SaveToFile;
var
lSaveTo: TppSaveToType;
lsSaveTemplateName: String;
lReport:TppReport;
begin
if (FListView.ItemType <> itReport) or (FListView.ItemName = '') then Exit;
Cursor := crHourGlass;
FListView.Cursor := crHourGlass;
try
FReportExplorer.LoadReport(FListView.ItemName, FListView.FolderId);
// assign Report object
lReport := FReportExplorer.Designer.Report;
if lReport <> nil then
begin
lSaveTo := lReport.Template.SaveTo;
lsSaveTemplateName := lReport.Template.Description;
{modify settings}
lReport.Template.SaveTo := stFile;
try
if lReport.Template.ShowFileSaveDialog then
begin
lReport.Template.Save;
end;
finally
lReport.Template.SaveTo := lSaveTo;
lReport.Template.Description := lsSaveTemplateName;
end;
end;
finally
//FReportExplorer.Designer.Report := nil;
//lReport.Free;
Cursor := crDefault;
FListView.Cursor := crDefault;
end;
end;

procedure TfrmReportExplorer.LoadFromFile;
var
lsSaveTemplateName: String;
lSaveTo: TppSaveToType;
lReport: TppReport;
lFolderID: integer;
lReportName: String;
begin

if( trvFolders.Selected <> nil) then
lFolderId := Integer(trvFolders.Selected.Data)
else
lFolderId := itAllFolders;


lReport := TppReport.Create(FReportExplorer.Designer); -- also I tried
.Create(nil) but it did not make any difference
if not lReport.Template.ShowFileOpenDialog then Exit;

{load template}
try
lReport.Template.LoadFromFile;
lSaveTo := lReport.Template.SaveTo;

lReport.Template.SaveTo := stDatabase;
lsSaveTemplateName := lReport.Template.Description;
lReport.Template.DatabaseSettings :=
dmRWApplication.ppReport.Template.DatabaseSettings;
lReportName := lReport.Template.FileName;
lReportName := ExtractFileName(ChangeFileExt(lReportName,''));
try
FReportExplorer.Designer.Report := lReport;
// check if report already exists

If not FReportExplorer.IsReport(lReportName, lFolderId) then
FReportExplorer.SaveReport(lReportName,lFolderId)
else
FReportExplorer.SaveReport(lReportName+' '+DateTimeToStr(Now),
lFolderId);

Except on E:Exception do
ShowMessage('Error during saving report into Data Base:'+
E.Message);
end;
if FReportExplorer.CurrentFolderId <> lFolderId then
FReportExplorer.CurrentFolderId := lFolderId;
Self.Refresh;
finally
lReport.Template.SaveTo := lSaveTo;
lReport.Template.Description := lsSaveTemplateName;
//FReportExplorer.Designer.Report := nil;
//lReport.Free;
end;

Comments

  • edited August 2005

    On thing I notice is that you are not using Designer.Report everywhere.
    There is only one instance of TppReport used for the entire application. You
    should not create a new instance or free that instance.

    Can you provide more details?

    1. SaveToFile

    a. What happens when you call this method?

    b. If you trace the source code, where does it go wrong?

    2. LoadFromFile

    a. What happens when you call this method?

    b. If you trace the source code, where does it go wrong?




    --
    Nard Moseley
    Digital Metaphors Corporation
    http://www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.