如何从后代组件中删除属性 [英] How do you remove a property from a descendent component

查看:92
本文介绍了如何从后代组件中删除属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个TListView后代组件...它可以正常工作,但是我想知道是否可以删除我不希望在后代中使用的TListView属性。我不想出现在对象检查器中的属性是LargeImages,RowSelect,ShowColumnHeader,ShowWorkAreas,ViewStyle,OwnerData,OnData和OnDataFind。后代只有一个viewstyle vsIcon。

I have created a TListView descendent component... It functions flawlessly, but I wonder if it is possible to remove a TListView property that I do not want in the descendent. The properties I do not want to appear in the object inspector are LargeImages, RowSelect, ShowColumnHeader, ShowWorkAreas, ViewStyle, OwnerData, OnData and OnDataFind. The descendent only has one viewstyle vsIcon.

这是组件的界面部分:

  TImageEnListView = class(TListView)
  private
    FImageList: TImageList;
    FImageIndex: integer;
    FStringList: TStringList;
    FThumbnailWidth: integer;
    FThumbnailHeight: integer;
    FIconVerticalSpacing: integer;
    FIconHorzontalSpacing: integer;
    FFolder: string;
    FShadowedThumbnail: boolean;
    FShowCaptions: boolean;
    FShowTips: boolean;
    FBackgroundWorker: TBackgroundWorker;
    FTaskDialog: TTaskDialog;
    procedure BackgroundWorkerWork(Worker: TBackgroundWorker);
    { Event after threading is complete }
    procedure BackgroundWorkerWorkComplete(Worker: TBackgroundWorker; Cancelled: Boolean);
    { Event for feedback to GUI }
    procedure BackgroundWorkerWorkFeedback(Worker: TBackgroundWorker; FeedbackID,
      FeedbackValue: Integer);
  public
   { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Clears thumbnails, fileList and imageList }
    procedure ClearThumbnails;
    procedure InfoTip(Sender: TObject; Item: TListItem; var InfoTip: string);
    procedure Data(Sender: TObject; Item: TListItem);
    procedure DataFind(Sender: TObject; Find: TItemFind; const FindString: string;
      const FindPosition: TPoint; FindData: Pointer; StartIndex: Integer; Direction:
      TSearchDirection;
      Wrap: Boolean; var Index: Integer);
    procedure FillItems;
    property BackgroundWorker: TBackgroundWorker read FBackgroundWorker;
  published
    { Published declarations }
    property Folder: string read FFolder write FFolder;
    property FileList: TStringList read FStringList write FStringList;
    property ImageList: TImageList read FImageList write FImageList;
    property ThumbnailWidth: integer read FThumbnailWidth write FThumbnailWidth default 170;
    property ThumbnailHeight: integer read FThumbnailHeight write FThumbnailHeight default 120;
    property ShadowedThumbnail: boolean read FShadowedThumbnail write FShadowedThumbnail default
      True;
    property ShowTips: boolean read FShowTips write FShowTips default False;
    property ShowCaptions: boolean read FShowCaptions write FShowCaptions default True;
  end;


推荐答案

TTCustomListView 而不是 TListView ,并仅公开要显示的属性和事件。您可以使用VCL源(在 ComCtrls 单元中)以完全相同的方式查看 TListView 的完成方式方式(当然, TListView 除外)。这是一个这样做的(非常无用的)示例:

Create your class from TTCustomListView instead of TListView, and just expose the properties and events you want to make visible. You can use the VCL source (in the ComCtrls unit) to see how it was done for TListView in exactly the same way (except TListView exposes them all, of course). Here's a (very useless) example of how to do so:

TImageEnListView = class(TCustomListView)
... other code
published
  // Only expose some of the properties that are protected
  // in TCustomListView. Meaningless from a use standpoint,
  // but demonstrates the technique
  property Columns;
  property ColumnClick;
  property Constraints;
  property DragCursor;
  property DragKind;
  property DragMode;
  property Enabled;
  property Font;
  property FlatScrollBars;
  property FullDrag;
  property GridLines;
  property HideSelection;
end;

对于没有 TCustom 祖先,您可以创建一个包装器类,并将要更改的类作为私有字段包含在其中,并且仅通过发布的新属性公开所需的功能。这样的事情应该会让您入门(我只是公开一两个属性,您可以从那里获取它):

For classes where you don't have a TCustom ancestor, you can create a wrapper class and include the class you want to alter as a private field within it, and only expose the functionality you want through new properties you publish. Something like this should get you started (I'll just expose a property or two, and you can take it from there):

type
  TMySpecialListView=class(TComponent)
  private
    FEnListView: TImageEnListView;
    function GetThumbnailHeight: Integer;
    function GetThumbnailWidth: Integer;
    procedure SetThumbnailHeight(Value: Integer);
    procedure SetThumbnailWidth(Value: Integer);
  public
    constructor Create(AOwner: TComponent); override;
  published
    property ThumbnailHeight: Integer read GetThumbnailHeight
      write SetThumbnailHeight;
    property ThumbnailWidth: Integer read GetThumbnailWidth
      write SetThumbnailWidth;
  end;

implementation

{ TMySpecialListView }

constructor TMySpecialListView.Create(AOwner: TComponent);
begin
  inherited;
  FEnhListView := TImageEnListView.Create(Self);
  FEnhListView.Parent := Self.Parent;
  // Set other properties needed like width and height. You
  // can get the ones you need from your current .dfm values
  // for a new blank form with your TImageEnListView dropped
  // on it.
end;

function TMySpecialListView.GetThumbnailHeight: Integer;
begin
  Result := FEnhListView.ThumbnailHeight;
end;

function TMySpecialListView.GetThumbnailWidth: Integer;
begin
  Result := FEnhListView.ThumbnailWidth;
end;

procedure TMySpecialListView.SetThumbnailHeight(Value: Integer);
begin
  if Value <> FEnhListView.ThumbnailHeight then
    FEnhListView.ThumbnailHeight := Value;
end;

procedure TMySpecialListView.SetThumbnailWidth(Value: Integer);
begin
  if Value <> FEnhListView.ThumbnailWidth then
    FEnhListView.ThumbnailWidth := Value;
end;

这篇关于如何从后代组件中删除属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆