Tutorial: Creating a User Function Library

Introduction

In this tutorial, you learn how to create a User Function Library that can be accessed from the Formulas Expert in the embedded Crystal Report Designer.

When developers create a Crystal report in the embedded Crystal Report Designer, they often create formula fields to use in the report. These formula fields consist of variables and functions. The embedded Crystal Report Designer comes with a large collection of existing functions.

However, in some scenarios a user may require the ability to create a customized function, in the form of a library that can be distributed across machines. The User Function Library provides this capability.

A User Function Library (UFL) is a .NET class library that has the following characteristics:

  • The project name is prefixed with the string "CRUFL".
  • The project consists of an interface and an implementation class.
  • Both the interface and the implementation class have Com and GUID attributes.
  • Upon compilation, the assembly is registered for COM Interop so that it is viewed as a COM object.
  • The assembly/COM object is added to the Global Assembly Cache so that it is available across all .NET applications on the machine.
  • This assembly/COM object (the User Function Library, or UFL) then becomes visible within the embedded Crystal Reports Designer as a customized function under "Functions>Additional Functions>u2lcom.dll".

Sample Code

This tutorial comes with Visual Basic and C# sample code that show the completed version of the project. Follow the instructions in this tutorial to create a new project or open the sample code project to work from a completed version.

The sample code is stored in folders that are categorized by language and project type. The folder names for each sample code version are as follows:

  • C# Class Library: CRUFL_CS_ExchangeRate
  • VB Class Library: CRUFL_VB_ExchangeRate

To locate the folders that contain these samples, see Tutorials' Sample Code Directory.

In this section: