Copy report at runtime?
I know this is kind of an object-pascal question, but it's coming up
related to RB:
I have a report created at design-time with multiple groups. I delete
some of the groups at run-time, based on how many groups the user has
selected on a form. After running the report, if the user changes the
groups desired and runs the report again, it bombs because some of the
groups are already deleted.
I'd like to operate and run on a copy/instance of the design-time report
at runtime, so that I can re-initialize it for the next run (without
closing the form).
TIA...
related to RB:
I have a report created at design-time with multiple groups. I delete
some of the groups at run-time, based on how many groups the user has
selected on a form. After running the report, if the user changes the
groups desired and runs the report again, it bombs because some of the
groups are already deleted.
I'd like to operate and run on a copy/instance of the design-time report
at runtime, so that I can re-initialize it for the next run (without
closing the form).
TIA...
This discussion has been closed.
Comments
load the template at runtime when you want to restore the report to the
original version with all of the groups defined.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
though, which I really try to avoid (it means updating the setup routine
and a definite new support issue).
Any other way to do it?
I use another TReport to accomplish a similar thing. Save the layout at
run-time into a memory stream and load that stream into the new TReport.
The user then edits the new TReport.
Cheers
Dean
I get the gist of what you're saying but don't know the methods involved.
MyReport.template.savetostream...
Thanks. I'm going to try saving it, deleting the groups, running the
report, and then just restoring it back to the same report again...
In the unit's implementation, I have:
msSaveReport : TMemoryStream ;
In the unit's formcreate, I have:
msSavePreport := TMemoryStream.create ;
MyReport.template.saveToStream(msSaveReport) ;
When the user clicks the run report button, I have:
msSaveReport.position := 0 ;
MyReport.template.loadFromStream(msSaveReport) ;
However, this "works" the first time the report is run but I get an av
the second time on the loadfromstream line.
When I modify the code to read:
MyReport.template.new ;
msSaveReport.position := 0 ;
MyReport.template.loadFromStream(msSaveReport) ;
I get an av on the template.new line.
how to do this. Killed it an now the code, with the template.new line,
works great.
The correct code for the record:
In the unit's implementation::
msSaveReport : TMemoryStream ;
In the unit's formcreate::
msSaveReport := TMemoryStream.create ;
MyReport.template.saveToStream(msSaveReport) ;
In the unit's formclose:
msSaveReport.free ;
In the buttonclick method to run the report:
MyReport.template.new ;
msSaveReport.position := 0 ;
MyReport.template.loadFromStream(msSaveReport) ;
// code to modify and run report follows...