Class RegisteredObjects
Contains all registered report items such as objects, export filters, wizards.
Inheritance
Inherited Members
Namespace: FastReport.Utils
Assembly: FastReport.OpenSource.dll
Syntax
public static class RegisteredObjects
Remarks
Use this class to register own components, wizards, export filters or another items that need to be serialized to/from a report file.
Examples
// register own wizard
RegisteredObjects.AddWizard(typeof(MyWizard), myWizBmp, "My Wizard", true);
// register own export filter
RegisteredObjects.AddExport(typeof(MyExport), "My Export");
// register own report object
RegisteredObjects.Add(typeof(MyObject), "ReportPage", myObjBmp, "My Object");
Properties
Objects
Root object for all registered objects.
Declaration
public static ObjectInfo Objects { get; }
Property Value
Type | Description |
---|---|
ObjectInfo |
Methods
Add(Type, String, Bitmap, String)
Registers an object in the specified category with button's image and text.
Declaration
public static void Add(Type obj, string category, Bitmap image, string text)
Parameters
Type | Name | Description |
---|---|---|
System.Type | obj | Type of object to register. |
System.String | category | Name of category to register in. |
Bitmap | image | Image for object's button. |
System.String | text | Text for object's button. |
Remarks
You must specify either the page type name or existing category name in the category parameter. The report objects must be registered in the "ReportPage" category or custom category that is registered in the "ReportPage" as well. The dialog controls must be registered in the "DialogPage" category or custom category that is registered in the "DialogPage" as well.
If you want to register an object that needs to be serialized, but you don't want to show it on the toolbar, pass empty string in the category parameter.
Examples
// register the report object
RegisteredObjects.Add(typeof(MyReportObject), "ReportPage", myReportObjectBmp, "My Report Object");
// register the dialog control
RegisteredObjects.Add(typeof(MyDialogControl), "DialogPage", myDialogControlBmp, "My Dialog Control");
// add a category and register an object inside it
RegisteredObjects.AddCategory("ReportPage,MyCategory", myCategoryBmp, "My Category");
// register another report object in MyCategory
RegisteredObjects.Add(typeof(MyReportObject), "ReportPage,MyCategory",
anotherReportObjectBmp, "Another Report Object");
Add(Type, String, Bitmap, String, Int32)
Registers an object in the specified category with button's image, text and object's flags.
Declaration
public static void Add(Type obj, string category, Bitmap image, string text, int flags)
Parameters
Type | Name | Description |
---|---|---|
System.Type | obj | Type of object to register. |
System.String | category | Name of category to register in. |
Bitmap | image | Image for object's button. |
System.String | text | Text for object's button. |
System.Int32 | flags | Integer value that will be passed to object's OnBeforeInsert method. |
Remarks
See the Add(Type, String, Bitmap, String) method for more details.
To learn about flags, see the
Add(Type, String, Bitmap, String, Int32, Boolean)
Registers an object in the specified category with button's image, text, object's flags and multi-insert flag.
Declaration
public static void Add(Type obj, string category, Bitmap image, string text, int flags, bool multiInsert)
Parameters
Type | Name | Description |
---|---|---|
System.Type | obj | Type of object to register. |
System.String | category | Name of category to register in. |
Bitmap | image | Image for object's button. |
System.String | text | Text for object's button. |
System.Int32 | flags | Integer value that will be passed to object's OnBeforeInsert method. |
System.Boolean | multiInsert | Specifies whether the object may be inserted several times until you select the "arrow" button or insert another object. |
Remarks
See the Add(Type, String, Bitmap, String) method for more details.
To learn about flags, see the
Add(Type, String, Int32)
Registers an object in the specified category.
Declaration
public static void Add(Type obj, string category, int imageIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Type | obj | Type of object to register. |
System.String | category | Name of category to register in. |
System.Int32 | imageIndex | Index of image for object's button. |
Add(Type, String, Int32, Int32)
Registers an object in the specified category.
Declaration
public static void Add(Type obj, string category, int imageIndex, int buttonIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Type | obj | Type of object to register. |
System.String | category | Name of category to register in. |
System.Int32 | imageIndex | Index of image for object's button. |
System.Int32 | buttonIndex | Index of object's button in toolbar. |
AddCategory(String, Bitmap, String)
Registers a category that may contain several report objects.
Declaration
public static void AddCategory(string name, Bitmap image, string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Category name. |
Bitmap | image | Image for category button. |
System.String | text | Text for category button. |
Remarks
Category is a button on the "Objects" toolbar that shows context menu with nested items when you click it. Consider using categories if you register several report objects. It can save space on the "Objects" toolbar. For example, FastReport registers one category called "Shapes" that contains the LineObject and different types of ShapeObject.
The name of category must starts either with "ReportPage," or "DialogPage," depending on what kind of controls do you need to regiter in this category: report objects or dialog controls. After the comma, specify the category name. So the full category name that you need to specify in the name parameter, must be something like this: "ReportPage,Shapes".
When register an object inside a category, you must specify the full category name in the category parameter of the Add method.
AddConnection(Type)
Registers data connection.
Declaration
public static void AddConnection(Type obj)
Parameters
Type | Name | Description |
---|---|---|
System.Type | obj | Type of connection. |
Remarks
The obj must be of DataConnectionBase type.
Examples
// register data connection
RegisteredObjects.AddConnection(typeof(MsSqlDataConnection));
AddConnection(Type, String)
Registers custom data connection.
Declaration
public static void AddConnection(Type obj, string text)
Parameters
Type | Name | Description |
---|---|---|
System.Type | obj | Type of connection. |
System.String | text | Name of connection. |
Remarks
The obj must be of DataConnectionBase type.
Examples
// register data connection
RegisteredObjects.AddConnection(typeof(MyDataConnection), "My Data Connection");
AddExport(Type, String)
Registers a new export filter.
Declaration
public static void AddExport(Type obj, string text)
Parameters
Type | Name | Description |
---|---|---|
System.Type | obj | Type of export filter. |
System.String | text | Text for export filter's menu item. |
Remarks
The obj must be of ExportBase type.
Examples
// register own export filter
RegisteredObjects.AddExport(typeof(MyExport), "My Export");
AddExport(Type, String, String)
Declaration
public static void AddExport(Type obj, string category, string text)
Parameters
Type | Name | Description |
---|---|---|
System.Type | obj | |
System.String | category | |
System.String | text |
AddExport(Type, String, String, Bitmap)
Declaration
public static void AddExport(Type obj, string category, string text, Bitmap image)
Parameters
Type | Name | Description |
---|---|---|
System.Type | obj | |
System.String | category | |
System.String | text | |
Bitmap | image |
AddExportCategory(String, String)
Register Export category.
Declaration
public static void AddExportCategory(string name, string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Category name. |
System.String | text | Category text. |
AddFunction(MethodInfo, String)
Adds a new function into the specified category.
Declaration
public static void AddFunction(MethodInfo function, string category)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodInfo | function | MethodInfo containing all necessary information about the function. |
System.String | category | The name of category to register the function in. |
Remarks
Your function must be a static, public method of a public class.
The following standard categories are registered by default:
- "Math"
- "Text"
- "DateTime"
- "Formatting"
- "Conversion"
- "ProgramFlow"
FastReport uses XML comments to display your function's description. To generate XML comments, enable it in your project's properties ("Project|Properties..." menu, "Build" tab, enable the "XML documentation file" checkbox).
Examples
The following example shows how to register own functions:
public static class MyFunctions
{
/// <summary>
/// Converts a specified string to uppercase.
/// </summary>
/// <param name="s">The string to convert.</param>
/// <returns>A string in uppercase.</returns>
public static string MyUpperCase(string s)
{
return s == null ? "" : s.ToUpper();
}
/// <summary>
/// Returns the larger of two 32-bit signed integers.
/// </summary>
/// <param name="val1">The first of two values to compare.</param>
/// <param name="val2">The second of two values to compare.</param>
/// <returns>Parameter val1 or val2, whichever is larger.</returns>
public static int MyMaximum(int val1, int val2)
{
return Math.Max(val1, val2);
}
/// <summary>
/// Returns the larger of two 64-bit signed integers.
/// </summary>
/// <param name="val1">The first of two values to compare.</param>
/// <param name="val2">The second of two values to compare.</param>
/// <returns>Parameter val1 or val2, whichever is larger.</returns>
public static long MyMaximum(long val1, long val2)
{
return Math.Max(val1, val2);
}
}
// register a category
RegisteredObjects.AddFunctionCategory("MyFuncs", "My Functions");
// obtain MethodInfo for our functions
Type myType = typeof(MyFunctions);
MethodInfo myUpperCaseFunc = myType.GetMethod("MyUpperCase");
MethodInfo myMaximumIntFunc = myType.GetMethod("MyMaximum", new Type[] { typeof(int), typeof(int) });
MethodInfo myMaximumLongFunc = myType.GetMethod("MyMaximum", new Type[] { typeof(long), typeof(long) });
// register simple function
RegisteredObjects.AddFunction(myUpperCaseFunc, "MyFuncs");
// register overridden functions
RegisteredObjects.AddFunction(myMaximumIntFunc, "MyFuncs,MyMaximum");
RegisteredObjects.AddFunction(myMaximumLongFunc, "MyFuncs,MyMaximum");
AddFunctionCategory(String, String)
Adds a new function category.
Declaration
public static void AddFunctionCategory(string category, string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | category | Short name of category. |
System.String | text | Display name of category. |
Remarks
Short name is used to reference the category in the subsequent AddFunction(MethodInfo, String) method call. It may be any value, for example, "MyFuncs". Display name of category is displayed in the "Data" window. In may be, for example, "My Functions".
The following standard categories are registered by default:
- "Math"
- "Text"
- "DateTime"
- "Formatting"
- "Conversion"
- "ProgramFlow"
Examples
This example shows how to register a new category:
RegisteredObjects.AddFunctionCategory("MyFuncs", "My Functions");
FindObject(Type)
Finds the registered object's info.
Declaration
public static ObjectInfo FindObject(Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type of object to find. |
Returns
Type | Description |
---|---|
ObjectInfo | The object's info. |
Remarks
This method can be used to disable some objects, for example:
RegisteredObjects.FindObject(typeof(PDFExport)).Enabled = false;
GetMethod(Type, String, Boolean)
Gets the method or null if method is not found
Declaration
public static Delegate GetMethod(Type type, string methodName, bool inheritance)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | Type for method finding |
System.String | methodName | Name for method finfing |
System.Boolean | inheritance | Use True value for inheritance the method from base type, use false for get the method only from the this type |
Returns
Type | Description |
---|---|
System.Delegate |
IsTypeRegistered(Type)
Checks whether the specified type is registered already.
Declaration
public static bool IsTypeRegistered(Type obj)
Parameters
Type | Name | Description |
---|---|---|
System.Type | obj | Type to check. |
Returns
Type | Description |
---|---|
System.Boolean | true if such type is registered. |
RegisterMethod(Type, String, Delegate)
Register and override the method with method name in the type. For property use the property name and _Get or _Set suffix.
Declaration
public static void RegisterMethod(Type type, string methodName, Delegate method)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | Type for registering method |
System.String | methodName | Name of method fir registering |
System.Delegate | method | Method for registering |