III - Functions
31- Introduction:
Like all good generators of states (and FR in fact left), one dispose of a mathematical or logical expression appraiser.
In this chapter, one takes account of the modifications made to FR with the patch 1.2.

The generator of expressions is as you will be able to see it slightly inspired of that of QR (in its form, but not in the content). This generator is the small stone which I bring to this huge work which is FR.

32- What is available out of standard
32.1 -the operators
 Type Logic >, <, BUT, AND, NOT, =, < >, > =, < = Mathematics -, *, +, /, MOD, DIV

For the neophytes, MOD corresponds to MODulo and DIV, corresponds to a division whom the result is an integer.

32.2 -The functions
32.21-Description in file FR.LNG

So that the generator of expression function correctly, it is necessary that the usable functions by FR be in more  described in the file FR.LNG for the simple reason that will allow it to display a help (very summary) on the selected function,  a help on the parameters which is useful also to know when launch the editor of parameters then, to allow to the editor to sort the functions by category.

For that, it is enough to add to file FR.LNG the following line:

FCT = CATEGORY  | FCT(<X>, <Y>, <Z >) | Help on the function
with:

•  FCT, it is the name of the function
•  CATEGORY, it is the name of the category whom depends the function.
•  FCT(<X>, <Y>, <Z >), it is the visualization of the necessary parameters with 3 maximum named parameters X,Y and Z.
•  Help., it is a small help which must make it possible to the user to understand the goal of the function.
| (AltGr+6) corresponds to the separators.

32.22 -The standards functions

Each parameter is separated by a comma and can be an expression, constants,  variable, field of data...
The constants of the alphanumeric type must be limited by a character ".
The variables are limited by ' [ ' and ' ] '.
The fields of data are limited like the variables and have the following format:  Dataset_Name. "Field_Name"

Functions of statistics

• SUM(<X >) : Turn over the sum of the values taken by < X >. < X > is generally a field of data.
• AVG(<X >) : Turn over the average of the values taken by < X >. < X > is generally a field of data.
• COUNT    : Meter.
• MIN(<X >) : Turn over the value minimum of the values taken by < X >. < X > is generally a field of data.
• MAX(<X >) : Turn over the maximum value of the values taken by < X >. < X > is generally a field of data.

Functions on the dates

• FORMATDATETIME(<X>, <Y >) : Turn over the compressed date (TDateTime) < Y > in the format < X >. < X > uses the standard description of Delphi for the formats.
• FORMATFLOAT(<X>, <Y >) : Turn over numerical < Y > in the format < X >. < X > uses the standard description of Delphi for the formats.
• STRTODATE(<X >) : Turn over the digital representation (TDateTime) of the chain < X >. < X > must respect the format of the dates.
• STRTOTIME(<X >) : Turn over the digital representation (TDateTime) of the chain < X >. < X > must respect the format of the hours.

Functions on the character strings

• LOWERCASE(<X >) : Turn over the chain < X > into small letter.
• UPPERCASE(<X >) : Turn over the chain < X > in capital letter.
• NAMECASE(<X >) : Turn over the chain < X > into small with the first letter in capital letter.
• COPY(<X>, <Y>, <Z >) : Turn over a under-chain of < X > since the position < Y > and a length < Z >.

Functions on the numerical ones

• FRAC(<X >) : Turn over the decimal part of numerical < X >.
• INT(<X >) : Turn over the whole part of numerical < X >.
• ROUND(<X >) : Turn over an integer corresponding to round of < X >.
• STR(<X >) : Turn over a chain by converting numerical < X >.

Logical functions

• IF(<X>, <Y>, <Z >) : Turn over < Y > if the expression < X > is checked if not < Z >.
It is of a disconcerting simplicity!

Here a source code to add the functions, POS and SQRT:

 `{*******************************************}` `{                                          }` `{           FastReport v2.2                } ` `{                                          } ` `{ Example of creation of functions         }` `{ (c) Guilbaud Olivier                     }` `{       golivier@bigfoot.com               } ` `{                                          } ` `{ FastReport:(c) 1998-99 by Tzyganenko A.  }` `{                                          } ` `{ Thank you to transmit your commantaires &}` `{ modifications                            } ` `{ This is a FREEWARE it can be freely used } ` `{.                                         } ` `{******************************************} ` `{Histo:                                    }` ```{03/06/99:  creation                                                                              Unit FR_OGFct; interface ``` `implementation ` ```Uses FR_Pars, FR_Class; / / Standard Declaration Type   / / Declaration of our TfrOGFunctionLibrary  TfrOGFunctionLibrary = class(TfrFunctionLibrary)   public    constructor Create; override;    Procedure DoFunction(FNo:Integer procedure;  p1, p2,               p3:Variant; VAr valley:String); override;   end; //************************** / / * TfrOGFunctionLibrary  //************************** constructor TfrOGFunctionLibrary.Create; begin  inherited Create; // Here, one declares all the functions // which one will treat (mini attention 3 characters)   with List do   begin    Add('POS');    ADD('SQRT');   end;``` ```end; // Ici one treats the functions Procedure TfrOGFunctionLibrary.DoFunction(FNo:Integer procedure;  p1, p2, p3:Variant; Var valley:String); VAr Par1, Par2:  Varying;    Result:  Variantying; begin  Try   Case FNo of  //FNo is a index of function declared in a constructor Create    0 : Begin   //function POS          Par1:=VarToStr(Parser.Calc(p1));           Par2:=VarToStr(Parser.Calc(P2));           Resultat:=Pos(Par1,Par2);        end;    1 : Resultat:=SQRT(Parser.Calc(P1));  //function SQRT   end;  Except   // Result String if Exception   Resultat:='Erreur fonction '+List.Strings[FNo];  end;  Val:=VarToStr(Resultat); // The Result is String end; //******************************** // Initialisation of functions in order to they ar taken``` ```// charge by F.R. // Warning : The methode to recode the bookshops of``` ```// limite (!!) the number to 31 Procedure DoInit; Begin   frRegisterFunctionLibrary(TfrOGFunctionLibrary); end; initialization   DoInit; end.```

The inside the file  FR.LNG, you append the folowing lines :

SQRT   = Math & Trigo | SQRT(<X>) |Turn over the square root of  <X>
POS     = Chaînes      | POS(<X>,<Y>) | Turn over the  position of the string <X> in  <Y>

The the trick is played ! an now i am waitting for your works