Search Results for

    Show / Hide Table of Contents

    Working with styles

    First of all, let us call to mind, what “style”, “set of styles” and “library of styles” are.

    Style is an element, which possesses a name and properties, and determines design attributes, i.e. color, font and frame. The style determines the way a report object should be designed. The objects such as TfrxMemoView have the Style property, which is a property intended to set the style name. When applying a value to this property, the style design attributes are copied to the object.

    A set of styles consists of several styles, which refer to a report. The TfrxReport component has the Styles property, which refers to the object of the TfrxStyles type. The set of styles also possesses a name. The set of styles determines design of a whole report.

    A styles library includes several sets of styles. It is convenient to perform a selection of a concrete set for report design with the help of the library.

    The TfrxStyleItem represents a style.

      TfrxStyleItem = class(TCollectionItem)
      public
        // Style name.
        property Name: String;
    
        // Background color.
        property Color: TColor;
    
        // Font.
        property Font: TFont;
    
        // Frame.
        property Frame: TfrxFrame;
      end;
    

    The set of styles is represented by the TfrxStyles class. It comprises methods for performing such set operations as reading, saving, adding, deleting, as well as searching for a style. The set of styles file has FS3 extension by default.

      TfrxStyles = class(TCollection)
      public
        // Creates the styles set. One can specify “nil” instead of “AReport,” however in this case a user would be unable to use the “Apply” method.
        constructor Create(AReport: TfrxReport);
    
        // Adds a new style.
        function Add: TfrxStyleItem;
    
        // Returns the style with the given name.
        function Find(const Name: String): TfrxStyleItem;
    
        // Applies a set to a report.
        procedure Apply;
    
        // Returns the list of the styles names.
        procedure GetList(List: TStrings);
    
        // Reads a set.
        procedure LoadFromFile(const FileName: String);
        procedure LoadFromStream(Stream: TStream);
    
        // Saves a set.
        procedure SaveToFile(const FileName: String);
        procedure SaveToStream(Stream: TStream);
    
        // The list of styles.
        property Items[Index: Integer]: TfrxStyleItem; default;
    
        // A set’s name.
        property Name: String;
      end;
    

    In conclusion, the last TfrxStyleSheet class represents a styles’ library. It has methods for the library reading/saving, as well as adding, deleting, and style sets’ searching.

      TfrxStyleSheet = class(TObject)
      public
       // Constructs a library.
        constructor Create;
    
       // Clears a library.
        procedure Clear;
    
       // Deletes a set with certain number.
        procedure Delete(Index: Integer);
    
       // Returns the list of the names of styles’ sets.
        procedure GetList(List: TStrings);
    
       // Loads a library.
        procedure LoadFromFile(const FileName: String);
        procedure LoadFromStream(Stream: TStream);
    
       // Saves a library.
        procedure SaveToFile(const FileName: String);
        procedure SaveToStream(Stream: TStream);
    
       // Adds a new set of styles to the library.
        function Add: TfrxStyles;
    
       // Returns a number of styles’ sets in the library.
        function Count: Integer;
    
       // Returns a set with the given name.
        function Find(const Name: String): TfrxStyles;
    
       // Returns a set number with the given name.
        function IndexOf(const Name: String): Integer;
    
       // The list of styles’ sets.
        property Items[Index: Integer]: TfrxStyles; default;
      end;
    
    Back to top © Copyright Fast Reports Inc.