delphi – 如何从后代组件中删除属性
发布时间:2020-12-15 10:04:43 所属栏目:大数据 来源:网络整理
导读:我创建了一个TListView后代组件…它完美地运行,但我想知道是否有可能删除后代中我不想要的TListView属性.我不想在对象检查器中显示的属性是LargeImages,RowSelect,ShowColumnHeader,ShowWorkAreas,ViewStyle,OwnerData,OnData和OnDataFind.后代只有一个views
|
我创建了一个TListView后代组件…它完美地运行,但我想知道是否有可能删除后代中我不想要的TListView属性.我不想在对象检查器中显示的属性是LargeImages,RowSelect,ShowColumnHeader,ShowWorkAreas,ViewStyle,OwnerData,OnData和OnDataFind.后代只有一个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公开它们之外).这是一个(非常无用的)如何做的例子:
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祖先的类,您可以创建一个包装类,并将要更改的类包含在其中的私有字段中,并且仅通过您发布的新属性公开所需的功能.这样的事情应该让你开始(我只是暴露一两个属性,你可以从那里拿走它): 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;
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
