gpt4 book ai didi

delphi - 如何从后代组件中删除属性

转载 作者:行者123 更新时间:2023-12-03 18:01:11 26 4
gpt4 key购买 nike

我已经创建了一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com