Initializing Custom Assembly Objects
업데이트: 2005년 12월 5일
In some cases, you may need to initialize property and field values in your custom assembly classes when you instantiate them. You will most likely need to initialize your custom classes with values available to you from the report's global object collections. You do this by overriding the OnInit method of the Code object of a report. To access OnInit, use the Code element of the report definition. There are two techniques for initializing property or field values of the classes in a custom assembly that you plan to use in your report: You can either declare and create a new instance of your class using OnInit, or you can call a publicly available method using OnInit.
Global Object Collections and Initialization
Several collections are available to you for initializing your custom class variables. You can use the Globals and User collections. The Parameters, Fields and ReportItems collections are not available to you at the point in the report lifecycle when the OnInit method is invoked. To use the shared collections, Globals or User, you need to include the Report object reference. For example, to initialize your custom class based on the current language of the user accessing the report, your Code element might look like the following:
<Code>
Dim m_myClass As MyClass
Protected Overrides Sub OnInit()
m_myClass = new MyClass(Report.User!Language, _
Report.Globals!ExecutionTime)
End Sub
</Code>
One way to initialize the property and field values of a class as shown previously is to declare your class and create a new instance of it by calling an overridden constructor.
Another way to initialize the property and field values of the classes in your custom assemblies is to call a publicly available method that you define from the OnInit method. You first need to add an instance name for your class in the report definition file. Once you have added the appropriate assembly reference and instance name, you can call your initialization method to initialize property and field values for your class. Your OnInit method might look like the following:
<Code>
Protected Overrides Sub OnInit()
m_myClass.MyInitializationMethod(Report.User!Language, _
Report.Globals!ExecutionTime)
End Sub
</Code>
For more information about adding an assembly reference and instance name for your custom class, see 방법: 보고서에 어셈블리 참조 추가(보고서 디자이너).
For more information about the global object collections, see 식에 전역 컬렉션 사용(Reporting Services).
Change History
Release | History |
---|---|
2005년 12월 5일 |
|
참고 항목
관련 자료
Using Custom Assemblies with Reports