Dynamic Components Hanging Around
Hi there,
I am creating some dynamic components (labels and DBText) on a subreport at
runtime. It works fine the first time but the second time I run this
report, the components that were created the first time the report was run
still appear on the report. I have tried report.publisher.reset and a
number of other things but I cannot seem to get the components to disappear
once the report has been run and then closed. It might be something very
obvious but I cannot work this out. The code is below:
i := 0;
dLeftPosition := 0;
SubReport := ppClSubReport1;
// Assign dynamic fields to report fields and labels
while i < DMRPSReports.ACDSClassListAndMarks.FieldCount do
begin
ClassListReportLabels := TppLabel.Create(rptClassListAndMarks);
ClassListReportLabels.Band := SUbreport.Report.GetBand(btHeader, 0);
ClassListReportLabels.Transparent := True;
ClassListReportLabels.Left := dLeftPosition;
ClassListReportLabels.Height := 0.3229;
ClassListReportLabels.Width := 0.4167;
ClassListReportLabels.Top := speMainHeader.Top;
ClassListReportLabels.WordWrap := True;
ClassListReportLabels.Caption :=
DMRPSReports.ACDSCLassListAndMarks.Fields.Fields[i].FieldName;
ClassListReportLabels.Font.Name := 'Arial';
ClassListReportLabels.Font.Size := 10;
ClassListReportLabels.Font.Style := [fsBold,fsItalic];
ClassListReportDBText := TppDBText.Create(rptClassListAndMarks);
ClassListReportDBText.DataPipeline := Subreport.DataPipeline;
ClassListReportDBText.DataField :=
DMRPSReports.ACDSCLassListAndMarks.Fields.Fields[i].FieldName;
ClassListReportDBText.Band := SUbreport.Report.GetBand(btDetail, 0);
ClassListReportDBText.Left := dLeftPosition;
ClassListReportDBText.Height := 0.1875;
ClassListReportDBText.Width := 0.4167;
ClassListReportDBText.Top := 0.0104;
ClassListReportDBText.Font.Name := 'Arial';
ClassListReportDBText.Font.Size := 10;
ClassListReportDBText.Font.Style := [];
dLeftPosition := dLeftPosition + ClassListReportDBText.Width + 0.0667;
i := i + 1;
end;
ppRgnDetail.Left := dLeftPosition;
ppRgnHeader.Left := dLeftPosition;
dbcAverageFM.Left := dbtFinalMark.Left;
Richard
I am creating some dynamic components (labels and DBText) on a subreport at
runtime. It works fine the first time but the second time I run this
report, the components that were created the first time the report was run
still appear on the report. I have tried report.publisher.reset and a
number of other things but I cannot seem to get the components to disappear
once the report has been run and then closed. It might be something very
obvious but I cannot work this out. The code is below:
i := 0;
dLeftPosition := 0;
SubReport := ppClSubReport1;
// Assign dynamic fields to report fields and labels
while i < DMRPSReports.ACDSClassListAndMarks.FieldCount do
begin
ClassListReportLabels := TppLabel.Create(rptClassListAndMarks);
ClassListReportLabels.Band := SUbreport.Report.GetBand(btHeader, 0);
ClassListReportLabels.Transparent := True;
ClassListReportLabels.Left := dLeftPosition;
ClassListReportLabels.Height := 0.3229;
ClassListReportLabels.Width := 0.4167;
ClassListReportLabels.Top := speMainHeader.Top;
ClassListReportLabels.WordWrap := True;
ClassListReportLabels.Caption :=
DMRPSReports.ACDSCLassListAndMarks.Fields.Fields[i].FieldName;
ClassListReportLabels.Font.Name := 'Arial';
ClassListReportLabels.Font.Size := 10;
ClassListReportLabels.Font.Style := [fsBold,fsItalic];
ClassListReportDBText := TppDBText.Create(rptClassListAndMarks);
ClassListReportDBText.DataPipeline := Subreport.DataPipeline;
ClassListReportDBText.DataField :=
DMRPSReports.ACDSCLassListAndMarks.Fields.Fields[i].FieldName;
ClassListReportDBText.Band := SUbreport.Report.GetBand(btDetail, 0);
ClassListReportDBText.Left := dLeftPosition;
ClassListReportDBText.Height := 0.1875;
ClassListReportDBText.Width := 0.4167;
ClassListReportDBText.Top := 0.0104;
ClassListReportDBText.Font.Name := 'Arial';
ClassListReportDBText.Font.Size := 10;
ClassListReportDBText.Font.Style := [];
dLeftPosition := dLeftPosition + ClassListReportDBText.Width + 0.0667;
i := i + 1;
end;
ppRgnDetail.Left := dLeftPosition;
ppRgnHeader.Left := dLeftPosition;
dbcAverageFM.Left := dbtFinalMark.Left;
Richard
This discussion has been closed.
Comments
In your case you are creating the components at runtime. The report,
subreport and the controls in the report are objects and they will exists
until they are freed. If you don't free the report object or load a new
report template then those dynamically created components will be used the
next time you print the report. Try loading a report template that is the
original copy if you want to run the report without those dynamic
components. The subreport has a report property so you could call
Subreport.Report.Template.LoadFromFile or LoadFromDatabase.
Resetting the publisher will only clear any cached pages from the last run
of the report, it won't affect the layout definition of the report.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
Thanks for replying. Doesn't the report object get freed when you close the
preview window or after it has been printed? The CreateReportFromDataset is
the example I am using for this and there is nothing in that example about
templates or nowhere the report gets freed manually. Basically I am doing
things in the same order as that report (i.e. create the components on the
report and then print it) but still no joy. The only difference is that the
example report has nothing on it but my report already has some components
before I start adding more.
Richard
I don't think I was very clear about what I am trying to do so here is an
example:
The report shows some student information aswell as assessment marks and
grades.
When I run the report the first time (for a paper) it has the following
fields
ID, Name, Status, Test 1, Test 2, Exam, Final Mark, Grade
When I run the report the second time (for a different paper with different
assessments, student and grades) it has the following fields
ID, Name, Status, Lab 1, Test 1, Test 2, Test 3, Test 4, Exam part 1, Exam
part 2, Final Mark, Grade
When I run this report the second time all the headings from the first time
will still be on the report so for example both the Test 1 (from when I ran
it the first time) and Lab 1 (from when I ran it the second time) labels
will both appear on the report (Lab 1 on top of the Test 1 label) but I want
the assessment labels and dbtext fields to be blown away every time I run
this report. The ID, Name, Status, Final Mark and Grade labels will appear
every time but the assessments differ from paper to paper. Hope this clears
things up a bit.
Richard
The example you are running only uses one instance of the report. It is
owned by the form and is freed when the form is freed. The report creates a
preview form when it runs that is freed when the preview form is closed, but
the repor tobject is still in existance. You shouldn't need to free the
report in this case. If you want to create new controls each time, then
before you create the controls, call Report.Template.New to clear out the
old components in the layout so you can start with an empty template. That
should get it working.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
I did manage to get around it by putting the components into a TList when
they were being created and then going through the TList and freeing them
once the report had been run. Thanks for your help.
Richard