Working with styles

Top  Previous  Next

First of all, let's remember what a “style”, a “set of styles” and a “library of styles” are.

 

A style is an element that has a name and properties, and that determines some design attributes such as color, font and frame. The style determines the way a report object is displayed. Objects such as “TfrxMemoView” have the Style property, which holds a style name. When a value is given to this property the style design attributes are applied to the object.

 

A set of styles consists of several styles, which are used in a report. The “TfrxReport” component has the “Styles” property, which points to an object of the “TfrxStyles” type. The set of styles also has a name. The set of styles determines the design appearance of a whole report.

 

A styles library includes several sets of styles. A specific style set can conveniently be selected for a report from a styles library.

 

 

“TfrxStyleItem” represents a style.

 

TfrxStyleItem = class(TCollectionItem)

public

 property Name: String;

 { style name }

 

 property Color: TColor;

 { background color }

 

 property Font: TFont;

 { font }

 

 property Frame: TfrxFrame;

 { frame }

end;

 

 

A set of styles is represented by the “TfrxStyles” class. It has methods for performing set operations such as reading, saving, adding and deleting, as well as searching for a style. A set of styles file has an “fs3” extension by default.

 

TfrxStyles = class(TCollection)

public

 constructor Create(AReport: TfrxReport);

 { creates the styles set;

   “nil” can be specified instead of “AReport,”

   however a user could not then use the “Apply” method }

 

 function Add: TfrxStyleItem;

 { adds a new style }

 

 function Find(const Name: String): TfrxStyleItem;

 { returns the style with the given name }

 

 procedure Apply;

 { applies a set to a report }

 

 procedure GetList(List: TStrings);

 { returns the list of style names }

 

 procedure LoadFromFile(const FileName: String);

 procedure LoadFromStream(Stream: TStream);

 { reads a set }

 

 procedure SaveToFile(const FileName: String);

 procedure SaveToStream(Stream: TStream);

 { saves a set }

 

 property Items[Index: Integer]: TfrxStyleItem; default;

 { the list of styles }

 

 property Name: String;

 { a set’s name }

 

 end;

 

 

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

 

TfrxStyleSheet = class(TObject)

public

 constructor Create;

 { constructs a library }

 

 procedure Clear;

 { clears a library }

 

 procedure Delete(Index: Integer);

 { deletes a set with specified index number }

 

 procedure GetList(List: TStrings);

 { returns the list of names of styles sets }

 

 procedure LoadFromFile(const FileName: String);

 procedure LoadFromStream(Stream: TStream);

 { loads a library }

 

 procedure SaveToFile(const FileName: String);

 procedure SaveToStream(Stream: TStream);

 { saves a library }

 

 function Add: TfrxStyles;

 { adds a new set of styles to the library }

 

 function Count: Integer;

 { returns the number of styles sets in the library }

 

 function Find(const Name: String): TfrxStyles;

 { returns a set with the specified name }

 

 function IndexOf(const Name: String): Integer;

 { returns a set number with the specified name }

 

 property Items[Index: Integer]: TfrxStyles; default;

 { the list of styles sets }

 

 end;