Search Results for

    Show / Hide Table of Contents

    Working with a list of variables

    The notion of variables was minutely explained in the corresponding chapter. Let us briefly call to mind the main points.

    A user can specify one or several 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 via the “Data tree” window. It is convenient to use variables for aliasing of compound expressions, which are often used in a report.

    It is necessary to use the “frxVariables” unit when working with variables. Variables are represented by the TfrxVariable class.

      TfrxVariable = class(TCollectionItem)
      published
        property Name: String; // Name of a variable
        property Value: Variant; // Value of a variable
      end;
    

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

      TfrxVariables = class(TCollection)
      public
        // Adds a variable to the end of the list
        function Add: TfrxVariable;
    
        // Adds a variable to the given position of the list
        function Insert(Index: Integer): TfrxVariable;
    
        // Returns the index of a variable with the given name
        function IndexOf(const Name: String): Integer;
    
        // Adds a variable to the specified category
        procedure AddVariable(const ACategory, AName: String; const AValue: Variant);
    
        // Deletes a category and all its variables
        procedure DeleteCategory(const Name: String);
    
        // Deletes a variable
        procedure DeleteVariable(const Name: String);
    
        // Returns the list of categories
        procedure GetCategoriesList(List: TStrings; ClearList: Boolean = True);
    
        // Returns the list of variables in the specified category
        procedure GetVariablesList(const Category: String; List: TStrings);
    
        // The list of variables
        property Items[Index: Integer]: TfrxVariable readonly;
    
        // Values of variables
        property Variables[Index: String]: Variant; default;
      end;
    

    If the list of variables is long, it is convenient to group it by categories. For example, when having the following list of variables:

    Customer name
    Account number
    In total
    Total vat
    

    one can represent it in the following way:

    Properties
      Customer name
      Account number
    Totals
      In total
      total vat
    

    There are the following limitations:

    • at least one category must be created

    • categories form the first level of the data tree, variables form the second one

    • categories cannot be nested

    • variables’ names must be unique within a whole list, not within a category

    Back to top © Copyright Fast Reports Inc.