Assign events to TppReport
Hello,
I do all my reports the way like in the tutorial (page 400..)
Put them on a form, create the Form and get the report.
That works fine...
Now I would like to know if a report was sent to the printer and not to
screen. Need to lock invoices after they have been printed..
So I had a look at
------------------------------------------
Tech Tip: Detecting whether Report was
Printed to the Printer
------------------------------------------
but the event never fires..
Maybe it's, because I just get the report and not the events in the
example.
Really have no ideas how to get it to work ...
Any ideas?
TIA
Ralf
(D7/RB9.03 Ent.)
procedure TfrmMain.LaunchReport;
var
lFormClass: TformClass;
liIndex:Integer;
lForm: TForm;
lReport: TppReport;
begin
liIndex := lbxReports.ItemIndex;
if (liIndex = -1) then Exit;
lFormClass := TFormClass(lbxReports.Items.Objects[liIndex]);
lForm := lFormClass.Create(Application);
lReport := TrbReportForm(lForm).Report;
// maybe possible to assign?
lReport.OnPrintDialogClose := ... <<
lReport.Print;
lForm.Free;
end;
I do all my reports the way like in the tutorial (page 400..)
Put them on a form, create the Form and get the report.
That works fine...
Now I would like to know if a report was sent to the printer and not to
screen. Need to lock invoices after they have been printed..
So I had a look at
------------------------------------------
Tech Tip: Detecting whether Report was
Printed to the Printer
------------------------------------------
but the event never fires..
Maybe it's, because I just get the report and not the events in the
example.
Really have no ideas how to get it to work ...
Any ideas?
TIA
Ralf
(D7/RB9.03 Ent.)
procedure TfrmMain.LaunchReport;
var
lFormClass: TformClass;
liIndex:Integer;
lForm: TForm;
lReport: TppReport;
begin
liIndex := lbxReports.ItemIndex;
if (liIndex = -1) then Exit;
lFormClass := TFormClass(lbxReports.Items.Objects[liIndex]);
lForm := lFormClass.Create(Application);
lReport := TrbReportForm(lForm).Report;
// maybe possible to assign?
lReport.OnPrintDialogClose := ... <<
lReport.Print;
lForm.Free;
end;
This discussion has been closed.
Comments
This is very similar to how the main reports demo works. You should be able
to implement the report events on the form that the report is located. I
did a quick test and was able to see the ShowMessage in the AfterPrint event
if the PrinterDevice was not nil. Be sure you are assigning the events of
the correct report.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
thanks, the demos are always a good point to start with...
What I did in my app is after I assigned the lReport I load the
template from a database by stream...
in the main demo I selected the rbViaWiz and tried to load the template
like this:
...
....
liIndex := lbxReports.ItemIndex;
if (liIndex = -1) then Exit;
lFormClass := TFormClass(lbxReports.Items.Objects[liIndex]);
lForm := lFormClass.Create(Application);
lReport := TrbReportForm(lForm).Report;
// now load the template
FPathName := ExtractFilePath(ParamStr(0));
{set the initial report template file name}
lReport.Template.FileName := FPathName + 'CustTab.rtm';
lReport.Template.LoadFromFile;
lReport.DeviceType := dtScreen;
// the events of ppReport don't fire anymore..
lReport.Print;
lForm.Free;
The idea was :
Select what kind of output should be generated (now I know the class),
then select the layout and assign it to the report...
Any idea?
TIA
Ralf
If you are loading templates, the events you assign to the report object
will no longer be valid. One option is to use RAP to keep all event code
local to the template.
--------------------------------------------
Article: Troubleshooting Lost Event Handlers
--------------------------------------------
Let's assume you have created a report in Delphi and assign an event
handlers to the OnPreviewFormCreate event of the report. The event is
generated by Delphi as:
procedure TForm1.ppReport1PreviewFormCreate(Sender: TObject);
You then save the report to an RTM file 'Report1.RTM.' The events are
stored as references only, and so the RTM contains:
object ppReport1: TppReport
.
.
OnPreviewFormCreate = ppReport1PreviewFormCreate
end
You then go on to work on a different report. Saving it with under then
name 'Report2.RTM'. Only this time, before you save the report you change
the report component name to: rptOrders. Delphi automatically updates the
event declaration for OnPreviewFormCreate event to:
procedure TForm1.rptOrdersPreviewFormCreate(Sender: TObject);
You then create two buttons on the form, one to load Report1 and preview,
the other to load Report2 and preview. When you run the app and click
Report1, you an error. This is because the Report1.RTM file contains a
reference to ppReport1PreviewFormCreate, a method which no longer exists (at
least with this name) in the form.
One answer is to load all your rtm files into the report component you will
be using for loading. Fix any errors, reassign any events that get cleared.
This will update your rtms to contain the proper event handler names.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com