TfrxPropertyEditor = class(TObject)  protected    procedure GetStrProc(const s: String);    function GetFloatValue: Extended;    function GetOrdValue: Integer;    function GetStrValue: String;    function GetVarValue: Variant;    procedure SetFloatValue(Value: Extended);    procedure SetOrdValue(Value: Integer);    procedure SetStrValue(const Value: String);    procedure SetVarValue(Value: Variant);  public    constructor Create(Designer: TfrxCustomDesigner); virtual;    destructor Destroy; override;    function Edit: Boolean; virtual;    function GetAttributes: TfrxPropertyAttributes; virtual;    function GetExtraLBSize: Integer; virtual;    function GetValue: String; virtual;    procedure GetValues; virtual;    procedure SetValue(const Value: String); virtual;    procedure OnDrawLBItem(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState); virtual;    procedure OnDrawItem(Canvas: TCanvas; ARect: TRect); virtual;    property Component: TPersistent readonly;    property frComponent: TfrxComponent readonly;    property Designer: TfrxCustomDesigner readonly;    property ItemHeight: Integer;    property PropInfo: PPropInfo readonly;    property Value: String;    property Values: TStrings readonly;  end;

你也可以继承以下任何一个类,这些类本身实现了一些处理相应类型的属性的基本功能。

  TfrxIntegerProperty = class(TfrxPropertyEditor)  TfrxFloatProperty = class(TfrxPropertyEditor)  TfrxCharProperty = class(TfrxPropertyEditor)  TfrxStringProperty = class(TfrxPropertyEditor)  TfrxEnumProperty = class(TfrxPropertyEditor)  TfrxClassProperty = class(TfrxPropertyEditor)  TfrxComponentProperty = class(TfrxPropertyEditor)

在这个类中定义了几个属性。

  • Component – 链接到父级组件(不是属性本身!),给定的属性属于该组件。
  • frComponent – 相同的,但被投到TfrxComponent类型(为了在某些情况下方便)。
  • Designer – 通往 告设计器的链接。
  • ItemHeight – 项目高度,属性在其中显示。它在OnDrawXXX中很有用。
  • Value – 显示为字符串的属性值。
  • Values – 值的列表。如果定义了 “paValueList “属性(见下文),这个属性将被填入GetValue方法中。
    function GetFloatValue: Extended;    function GetOrdValue: Integer;    function GetStrValue: String;    function GetVarValue: Variant;    procedure SetFloatValue(Value: Extended);    procedure SetOrdValue(Value: Integer);    procedure SetStrValue(const Value: String);    procedure SetVarValue(Value: Variant);

你应该使用与属性类型相对应的方法。因此,如果属性是 “Integer “类型的,就使用GetOrdValue和SetOrdValue方法。这些方法也用于处理TObject类型的属性,因为这种属性包含32位对象地址。在这种情况下,只要做以下类型的转换就可以了,比如说。

MyFont := TFont(GetOrdValue)
TfrxPropertyAttribute = (paValueList, paSortList, paDialog, paMultiSelect, paSubProperties, paReadOnly, paOwnerDraw);TfrxPropertyAttributes = set of TfrxPropertyAttribute;

属性分配是按以下方式实现的:

  • paValueList – 属性代表下拉式的数值列表。这个功能以 “颜色 “属性为例)。如果这个属性存在,GetValues方法应该被重写。
  • paSortList – 对列表元素进行排序。它与paValueList一起使用。
  • paSubProperties – 属性是TPersistent类型的对象,并且有它自己的属性,这些属性也应该被显示。这个功能在 “字体 “属性中得到了体现)。
  • paOwnerDraw – 属性值的绘制是通过OnDrawItem方法进行的。如果 “paValueList “属性被定义,那么下拉列表的绘制是通过OnDrawLBItem方法进行的。

GetValue方法应该以字符串形式返回属性值(它将显示在对象检查器中)。如果你继承了TfrxPropertyEditor基本类,有必要覆盖这个方法。

SetValue方法是用来设置属性值转移为字符串。如果你继承自TfrxPropertyEditor基本类,就有必要覆盖这个方法。

procedure frxPropertyEditors.Register(PropertyType: PTypeInfo; ComponentClass: TClass; const PropertyName: String; EditorClass: TfrxPropertyEditorClass);
  • PropertyType – 关于属性类型的信息,通过 “TypeInfo “系统函数传输,例如TypeInfo(String)。
{ TFont property editor displays editor button(...) }{ inherit from ClassProperty }type TfrxFontProperty = class(TfrxClassProperty)  public    function Edit: Boolean; override;    function GetAttributes: TfrxPropertyAttributes; override;  end;function TfrxFontProperty.GetAttributes: TfrxPropertyAttributes;begin  {  property has nested properties and  editor. It cannot be edited manually }  Result := [paMultiSelect, paDialog, paSubProperties, paReadOnly];end;function TfrxFontProperty.Edit: Boolean;var  FontDialog: TFontDialog;begin  { create standard dialogue }  FontDialog := TFontDialog.Create(Application);  try    { take  property value }    FontDialog.Font := TFont(GetOrdValue);    FontDialog.Options := FontDialog.Options + [fdForceFontExist];    { display dialogue }    Result := FontDialog.Execute;    { bind new value }    if Result then      SetOrdValue(Integer(FontDialog.Font));  finally    FontDialog.Free;  end;end;{ registration }frxPropertyEditors.Register(TypeInfo(TFont), nil, '', TfrxFontProperty);
{ TFont.Name property editor displays  drop-down list of available fonts }{ inherit from StringProperty, as property is of string type }type  TfrxFontNameProperty = class(TfrxStringProperty)  public    function GetAttributes: TfrxPropertyAttributes; override;    procedure GetValues; override;  end;function TfrxFontNameProperty.GetAttributes: TfrxPropertyAttributes;begin  Result := [paMultiSelect, paValueList];end;procedure TfrxFontNameProperty.GetValues;begin  Values.Assign(Screen.Fonts);end;{ registration }frxPropertyEditors.Register(TypeInfo(String), TFont, 'Name', TfrxFontNameProperty);
{ TPen.Style property editor displays picture, which is pattern of selected style }type  TfrxPenStyleProperty = class(TfrxEnumProperty)  public    function GetAttributes: TfrxPropertyAttributes; override;    function GetExtraLBSize: Integer; override;    procedure OnDrawLBItem(Control: TWinControl; Index: Integer;      ARect: TRect; State: TOwnerDrawState); override;    procedure OnDrawItem(Canvas: TCanvas; ARect: TRect); override;  end;function TfrxPenStyleProperty.GetAttributes: TfrxPropertyAttributes;begin  Result := [paMultiSelect, paValueList, paOwnerDraw];end;{ method draws thick horizontal line with selected style }procedure HLine(Canvas: TCanvas; X, Y, DX: Integer);var  i: Integer;begin  with Canvas do  begin    Pen.Color := clBlack;    for i := 0 to 1 do    begin      MoveTo(X, Y - 1 + i);      LineTo(X + DX, Y - 1 + i);    end;  end;end;{ drawing drop-down list }procedure TfrxPenStyleProperty.OnDrawLBItem(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);begin  with TListBox(Control), TListBox(Control).Canvas do  begin    FillRect(ARect);    TextOut(ARect.Left + 40, ARect.Top + 1, TListBox(Control).Items[Index]);    Pen.Color := clGray;    Brush.Color := clWhite;    Rectangle(ARect.Left + 2, ARect.Top + 2, ARect.Left + 36, ARect.Bottom - 2);    Pen.Style := TPenStyle(Index);    HLine(TListBox(Control).Canvas, ARect.Left + 3, ARect.Top + (ARect.Bottom - ARect.Top) div 2, 32);    Pen.Style := psSolid;  end;end;{ drawing property value }procedure TfrxPenStyleProperty.OnDrawItem(Canvas: TCanvas; ARect: TRect);begin  with Canvas do  begin    TextOut(ARect.Left + 38, ARect.Top, Value);    Pen.Color := clGray;    Brush.Color := clWhite;    Rectangle(ARect.Left, ARect.Top + 1, ARect.Left + 34, ARect.Bottom - 4);    Pen.Color := clBlack;    Pen.Style := TPenStyle(GetOrdValue);    HLine(Canvas, ARect.Left + 1, ARect.Top + (ARect.Bottom - ARect.Top) div 2 - 1, 32);    Pen.Style := psSolid;  end;end;{ return  picture width }function TfrxPenStyleProperty.GetExtraLBSize: Integer;begin  Result := 36;end;{ registration }frxPropertyEditors.Register(TypeInfo(TPenStyle), TPen, 'Style', TfrxPenStyleProperty);

如果您对 FastReport 感兴趣,欢迎加入 FastReport QQ 交流群:702295239

还想要更多吗可以点击阅读【FastReport 表2021最新资源盘点】查找需要的教程资源。上是FastReport .NET慧正在 火热销售中!>>查看价格详情

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年6月5日
下一篇 2021年6月5日

相关推荐

发表回复

登录后才能评论