Working with a list of variables

Top  Previous  Next

The notion of variables was explained in detail in the corresponding chapter. Let's briefly call to mind the main points.

 

A user can specify one or more variables in a report. A value or an expression, which will be automatically calculated when referring to a variable, can be assigned to every variable. Variables can be visually inserted into a report from the “Data tree” pane. It is convenient to use variables as aliases for compound expressions, which are often used in reports.

 

The “frxVariables” unit must be used in the project when working with variables. Variables are represented by the “TfrxVariable” class.

 

TfrxVariable = class(TCollectionItem)

published

 property Name: String;

 ( the name of the variable }

 

 property Value: Variant;

 { the value of the variable }

 end;

 

 

The list of variables is represented by the “TfrxVariables” class. It contains all the methods necessary for working with the list.

 

TfrxVariables = class(TCollection)

public

 function Add: TfrxVariable;

 { adds a variable to the end of the list }

 

 function Insert(Index: Integer): TfrxVariable;

 { adds a variable at the given position in the list }

 

 function IndexOf(const Name: String): Integer;

 { returns the index of the variable with the given name }

 

 procedure AddVariable(const ACategory, AName: String;

                       const AValue: Variant);

 { adds a variable to the specified category }

 

 procedure DeleteCategory(const Name: String);

 { deletes a category and all its variables }

 

 procedure DeleteVariable(const Name: String);

 { deletes a variable }

 

 procedure GetCategoriesList(List: TStrings; ClearList: Boolean = True);

 { returns the list of categories }

 

 procedure GetVariablesList(const Category: String; List: TStrings);

 { returns the list of variables in the specified category }

 

 property Items[Index: Integer]: TfrxVariable readonly;

 { the list of variables }

 

 property Variables[Index: String]: Variant; default;

 { value of specified variable }

 

 end;

 

 

When the list of variables is long it can be convenient to group the variables by categories. For example, having the following list of variables:

 

Customer name

Account number

in total

total vat

 

they can be represented it in the following way:

 

Properties

 Customer name

 Account number

Totals

 in total

 total vat

 

There are some limitations:

 

- at least one category must be created

- categories form the first level of the data tree, variables form the second

- categories cannot be nested

- variable names must be unique within the whole list, not just within a category