Report variables not accessible - workaround.

Stimulsoft Reports.NET discussion
Mark Smith
Posts: 37
Joined: Tue Jun 13, 2006 8:59 am
Location: Yorkshire, UK

Report variables not accessible - workaround.

Post by Mark Smith »

Hi -

I need to read some data from the Report Preview to allow my users to do some stuff with the report.

I'm having a problem reading the report variables in Preview mode. If you are in the designer and press the 'Preview' button, (not the preview tab), and open the report preview form in an MDI application, the report variables are inaccessible.

eg
MyDesigner.Report.Dictionary.Variables.Count is > 0 but
PreviewForm.Report.Dictionary.Variables.Count == 0

I've seen the suggestion that one uses the PreviewForm.Report["varname"] approach, but this only works if you have a compiled report accessible through PreviewForm.Report.CompiledReport, which is null.

Attempting to compile the report gives an exception - "report does not need compiling".

Setting PreviewForm.Report.NeedsCompiling to false will allow PreviewForm.Report.Compile() to run, but it gives an exception with an enormous list of errors. I can email these to you if you want.

Right now, my workaround is probably to add some extra properties to the DataSet associated with the report, but this is a hack.

How can I see report variables from the Report Preview Form in the rest of my application?
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Report variables not accessible - workaround.

Post by Vital »

Sorry, but when report is compiled all variables convert to class fields and does not exis more in report dictionary.
You can assign it with report[variableName] or check it existing with method report.IsVariableExist(variableName).
Thank you.
Mark Smith
Posts: 37
Joined: Tue Jun 13, 2006 8:59 am
Location: Yorkshire, UK

Report variables not accessible - workaround.

Post by Mark Smith »

Hi Vital -
You can assign it with report[variableName] or check it existing with method report.IsVariableExist(variableName).
This does not work though, since Report.CompiledReport is null. I already checked this, and you cannot compile the report at this point as I mentioned.

Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Report variables not accessible - workaround.

Post by Vital »

If report is compiled (NeedsCompiling = false) you need use IsVariableExist. In other case you need use report.Dictionary.Variables.

Thank you.
Mark Smith
Posts: 37
Joined: Tue Jun 13, 2006 8:59 am
Location: Yorkshire, UK

Report variables not accessible - workaround.

Post by Mark Smith »

Hi Vital -

Please check this.

If you are looking at a StiPreviewForm then CompiledReport is null and NeedsCompiling is false. Designer is also false, sadly. If this held a pointer back to the original designer that launched the preview form then that would solve a problem I will be facing tomorrow :-)

Here is what you see if you use the VS2005.NET Immediate Window to examine a report shown from an StiPreviewForm:

? this.ActivePreview.Report
{Report}
[Reports.Report]: {Report}
base {System.ComponentModel.Component}: {Report}
...
CompiledReport: null
...
IsCompiled: false
...
NeedsCompiling: false
...
PreviewControl: null
PreviewForm: null
...

this.ActivePreview is a reference to the current MDI child when it is an StiPreviewForm.
Mark Smith
Posts: 37
Joined: Tue Jun 13, 2006 8:59 am
Location: Yorkshire, UK

Report variables not accessible - workaround.

Post by Mark Smith »

Hi Edward, Vital

My hack with using a tables ExtendedProperties seems to work, but really you need to re-examine why neither the variables nor the compiled report are available.

In case anyone else has this problem, here's how I go around it:

Code: Select all

// getting data, setting extended properties before showing preview
DataSet ds = formsTool.ReadAllData();
ds.Tables[0].ExtendedProperties[ReportController.cGWSSpaceName] = SpaceName;
ds.Tables[0].ExtendedProperties[ReportController.cGWSToolName] = ToolName;
ds.Tables[0].ExtendedProperties[ReportController.cGWSDataName] = DataName;
report.RegData(ds);
report.Show(this); // this is an MDI application
and when I want these values back:

Code: Select all

// called from MDI Main menu
if (this.ActivePreview != null) {
    Stimulsoft.Report.StiReport report = this.ActivePreview.Report;
    object data = report.DataStore[0].Data;

     if (data is System.Data.DataTable) {
         System.Data.DataTable table = data as System.Data.DataTable;
          string SpaceName = table.ExtendedProperties[ReportController.cGWSSpaceName] as string;
          string ToolName = table.ExtendedProperties[ReportController.cGWSToolName] as string;
          string DataName = table.ExtendedProperties[ReportController.cGWSDataName] as string;

          // Retrieve the data
          ApplicationController.LoadReportData(report, SpaceName, ToolName, DataName);

          this.ActivePreview.Refresh();
          report.Render();
    }
}
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

Report variables not accessible - workaround.

Post by Brendan »


Hi Mark,
As far as I know, if the Property "NeedsCompiling" is false the the current report object is the actual compiled report so the "CompiledReport" property is going to be null.

When you want to retreive your variable values does the following not work?

Code: Select all

if (this.ActivePreview != null) {
    Stimulsoft.Report.StiReport report = this.ActivePreview.Report;

    string SpaceName = report[ReportController.cGWSSpaceName] as string;
    string ToolName = report[ReportController.cGWSToolName] as string;
    string DataName = report[ReportController.cGWSDataName] as string;

    // Retrieve the data
    ApplicationController.LoadReportData(report, SpaceName, ToolName, DataName);

    this.ActivePreview.Refresh();
    report.Render();
}
Mark Smith
Posts: 37
Joined: Tue Jun 13, 2006 8:59 am
Location: Yorkshire, UK

Report variables not accessible - workaround.

Post by Mark Smith »

Hi Brendan -

Many thanks for posting.

No, because the Report that you've got is an instance of StiReport, not an instance of the compiled report. If you look at the code for the this[index] method, it wants to use CompiledReport, which is null and failing that, reverts to the StiReport instance which does not have the property.

IsVariableExist() fails for the same reason.

Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Report variables not accessible - workaround.

Post by Vital »

We do some modifications in our code. Please get new version in next Tuesday and check again.

Thank you.
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

Report variables not accessible - workaround.

Post by Brendan »


Hi Mark,
This is probably of no benefit but this is a sample of what I do.

Sample Download

Maybe there is a difference in versions that we use
Post Reply