作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经创建了一个 TListView 后代组件...它运行完美,但我想知道是否可以删除我不希望在后代中使用的 TListView 属性。我不想在对象检查器中出现的属性是 LargeImages、RowSelect、ShowColumnHeader、ShowWorkAreas、ViewStyle、OwnerData、OnData 和 OnDataFind。后代只有一个viewstyle vsIcon。
这是组件的接口(interface)部分:
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
创建你的类(class)而不是 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
祖先的类,您可以创建一个包装类并将要更改的类作为私有(private)字段包含在其中,并且只公开您想要的功能通过您发布的新属性。像这样的东西应该可以帮助您入门(我将只公开一两个属性,您可以从那里获取它):
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;
关于delphi - 如何从后代组件中删除属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15961579/
我是一名优秀的程序员,十分优秀!