Working with styles
类型是一个元素,它具有名称、属性及決定设计属性,例如颜色(color)、字型(font)及外框(frame)。类型決定报表物件应该如何显示,这个物件像是TfrxMemoView 有Style 属性,此处必须设定为类型的名称,当套用一个值到此属性,此类型的设计属性将套用到此物件。类型的集合包含数个类型,它参考到同一份报表。“TfrxReport” 元件提供“Styles” 属性,它参考到物件的“TfrxStyles” 类型,类型的集合也必须具有名称,类型的集合代表整份报表的设计(展现方式)。
类型库包括数个类型的集合,透过类型库的协助,我们可以方便的管理类型的集合。
TfrxStyleItem 代表类型。
TfrxStyleItem = class(TCollectionItem)
public
property Name: String;
Style name.
property Color: TColor;
Background color.
property Font: TFont;
Font.
property Frame: TfrxFrame;
Frame.
end;
TfrxStyles 类别代表类型的集合,它是由读取(reading) 、储存(saving) 、新增(adding) 、刪除(deleting) 及搜寻等操作的方法(method)所組成。类型集合预置的后缀名为”.FS3” 。
TfrxStyles = class(TCollection)
public
constructor Create(AReport: TfrxReport);建立类型集。
function Add: TfrxStyleItem;加入新类型。
function Find(const Name: String): TfrxStyleItem;返回指定名称的类型。procedure Apply;套用报表类型。
procedure GetList(List: TStrings);返回类型名称清单。
procedure LoadFromFile(const FileName: String);
procedure LoadFromStream(Stream: TStream);读取类型集。
procedure SaveToFile(const FileName: String);
procedure SaveToStream(Stream: TStream);储存类型集。
property Items[Index: Integer]: TfrxStyleItem; default;类型清单。property Name: String;类型集名称。
end;
最后,“TfrxStyleSheet” 类别代表类型库,它提供读取/储存和新增、刪除及类型集的搜寻等方法。
TfrxStyleSheet = class(TObject)
public
constructor Create;建立类型库procedure Clear;清除类型库
procedure Delete(Index: Integer);刪除指定索引编号的类型procedure GetList(List: TStrings);返回类型集合名称清单.
procedure LoadFromFile(const FileName: String);procedure LoadFromStream(Stream: TStream);载入类型库
procedure SaveToFile(const FileName: String);procedure SaveToStream(Stream: TStream);储存类型库
function Add: TfrxStyles;加入新的类型至类型库function Count: Integer;返回类型库的类型集个数
function Find(const Name: String): TfrxStyles;返回集合名称的类型集function IndexOf(const Name: String): Integer;返回类型集名称的索引编号property Items[Index: Integer]: TfrxStyles; default;类型集清单
end;
Creation of style sets 建立类型集
下列的程序代码示范如何建立类型集,并增加两个类型至类型集。在这些操作完成之后,这些类型将套用至报表。
Var
Sttyle: TfrxStyleItem;
Styles: TfrxStyles;
Styles := TfrxStyles.Create(nil);
{ 第一个类型}
Style := Styles.Add;
Style.Name := 'Style1';
Style.Font.Name := 'Courier New';
{ 第二个类型}
Style := Styles.Add;
Style.Name := 'Style2';
Style.Font.Name := 'Times New Roman';
Style.Frame.Typ := [ftLeft, ftRight];
{ 套用类型至报表}
frxReport1.Styles := Styles;
你可以使用普通的方法建立及使用类型集:
Var
Style: TfrxStyleItem;
Styles: TfrxStyles;
Styles := frxReport1.Styles;
Styles.Clear;
{ 第一个类型 }
Style := Styles.Add;
Style.Name := 'Style1';
Style.Font.Name := 'Courier New';
{ 第二个类型 }
Style := Styles.Add;
Style.Name := 'Style2';
Style.Font.Name := 'Times New Roman';
Style.Frame.Typ := [ftLeft, ftRight];
{ 套用类型至报表 }
frxReport1.Styles.Apply;
Modifying/adding/deleting a style
修改指定名称的类型:
S
var
tyle: TfrxStyleItem;
Styles: TfrxStyles;
Styles := frxReport1.Styles;
{ search for a style}
Style := Styles.Find('Style1');
{ modify the font size }
Style.Font.Size := 12;
加入类型至报表类型集:
Var
Style : TfrxStyleItem;
Styles: TfrxStyles;
Styles := frxReport1.Styles;
{ 新增类型 }
Style := Styles.Add;
Style.Name := 'Style3';
刪除指定名称的类型:
S
var
tyle: TfrxStyleItem;
Styles: TfrxStyles;
Styles := frxReport1.Styles;
{ 刪除类型 }
Style := Styles.Find('Style3');
Style.Free;
修改完成之后,你应该调用套用(“Apply”) 方法:
{ 套用修改后的结果 }
frxReport1.Styles.Apply;
Saving/restoring a set 存取模板
frxReport1.Styles.SaveToFile('c:\1.fs3');
frxReport1.Styles.LoadFromFile('c:\1.fs3');
Clear report styles
执行的方法有两种:
frxReport1.Styles.Clear;
或frxReport1.Styles := nil;
Styles library creation
下列的范例示范如何建立类型库及新增两个类型至类型库。
Var
Styles: TfrxStyles;
StyleSheet: TfrxStyleSheet;
StyleSheet := TfrxStyleSheet.Create;
{ the first set }
Styles := StyleSheet.Add;
Styles.Name := 'Styles1';
{ here one can add styles to the Styles set}
{ the second set }
Styles := StyleSheet.Add;
Styles.Name := 'Styles2';
{ here one can add styles to the Styles set}
Displaying a list of style sets, and application of a
selected style
类型库为经常被使用在显示特定的输出类型,这些类型可透过“ComboBox” 或“ListBox.” 由使用者选取,并套用至报表。显示类型清单:
StyleSheet.GetList(ComboBox1.Items);套用类型至报表:
frxReport1.Styles := StyleSheet.Items[ComboBox1.ItemIndex];
或
frxReport1.Styles := StyleSheet.Find[ComboBox1.Text];
Modification/adding/deleting of a styles set
修改指定名称的类型集:
Var
Styles: TfrxStyles;
StyleSheet: TfrxStyleSheet;
{ search for the required set }
Styles := StyleSheet.Find('Styles2');
{ modify a style with the Style1 name from the found set }
with Styles.Find('Style1') do
Font.Name := 'Arial Black';
新增类型至类型集:
Var
Styles: TfrxStyles;
StyleSheet: TfrxStyleSheet;
{ the third set }
Styles := StyleSheet.Add;
Styles.Name := 'Styles3';
从类型集中刪除指定类型:
ivar: Integer;
StyleSheet: TfrxStyleSheet;
{ search for the third set }
i := StyleSheet.IndexOf('Styles3');
{ if find, delete }
if i <> -1 then
StyleSheet.Delete(i);
Saving and loading a styles library( 储存及载入类型库)
类型库预置的后缀名为”FSS” 。
Var
StyleSheet: TfrxStyleSheet;
StyleSheet.SaveToFile('c:\1.fss');
StyleSheet.LoadFromFile('c:\1.fss');
本文来自博客园,作者:del88,转载请注明原文链接:https://www.cnblogs.com/del88/archive/2012/01/06/2314598.html