|
EK RTF report components for .Net
|
User Defined Function, or UDF is an extension to a report language. For example, if it is necessary to obtain some value, and EkRtf component does not support that function, a new, external function could be written and compiled to accomplish this task.
There is a step by step instruction, how to create a new function.
1) Add EkUDFList component to your project. In EkRtf components set property UDFList according to your EkUDFList component:

2) In EkUDFList context menu select "Functions ..." command to open an interface for adding new function:

3) Press "Add" button. New item named UDF1 will appear. Type in FunctionName property value in order to set the name of your function:

You will use this name in your reports to call the function.
4) Activate Event tab of the Properties window. Type in OnCalculate event property and then press Enter to create an event handler procedure for your function:

IDE will generate an empty procedure for you. Input parameters are coming in a variable of type EkUDFEventArgs. Result of the function should be stored in e.UDFResult object. Constants, report variables and expression results are all passed as EkReportVariable in input parameters. Database fields are passed as EkDataField objects. The type of the UDFResult is depending on ResultType property of your function. There is an example of event handler code shown below:
|
C# example: |
|
using EkRtfBase; ................ private void NewUserFunctionCode(object Sender, EkRtfFunc.EkUDFEventArgs e) { // **** This is NewUserFunction **** string s; s = ""; //if report variable or constant passed as function argument if (e.Args[0] is EkReportVariable) { s=((EkReportVariable)e.Args[0]).AsString; } //if data field passed as function argument if (e.Args[0] is EkDataField) { s = Convert.ToString(((EkDataField)e.Args[0]).Value); } //The result ((EkReportVariable)e.UDFResult).AsString=s; } |
|
Pascal example: |
|
uses EkRtfReport, EkRtfFunc, EkRtfBase; ................ procedure WinForm1.NewUserFunctionCode(Sender: System.Object; e: EkRtfFunc.EkUDFEventArgs); var s:string; begin // **** This is NewUserFunction **** s := ''; //if report variable or constant passed as function argument if (e.Args[0] is EkReportVariable) then begin s:=EkReportVariable(e.Args[0]).AsString; end; //if data field passed as function argument if (e.Args[0] is EkDataField) then begin s := Convert.ToString(EkDataField(e.Args[0]).Value); end; //The result EkReportVariable(e.UDFResult).AsString:=s; end; |
In the RTF report template this function may looks like this:
\NewUserFunction(‘Text argument’)\
\NewUserFunction(Customers:CustomerID)\
The result document will be:
Text argument
ALFKI
See also EkUDFList Insert picture example
|
Copyright (c) 2007. All rights reserved.
|