Delphi 如何为我的组件创建文件夹(目录)属性编辑器?
德尔福2010 如何为我的组件创建文件夹(目录)属性编辑器 我可以使用以下方法轻松创建一个文件名属性:Delphi 如何为我的组件创建文件夹(目录)属性编辑器?,delphi,components,delphi-2010,custom-component,propertyeditor,Delphi,Components,Delphi 2010,Custom Component,Propertyeditor,德尔福2010 如何为我的组件创建文件夹(目录)属性编辑器 我可以使用以下方法轻松创建一个文件名属性: TFileProperty = class(TStringProperty) public function GetAttributes: TPropertyAttributes; override; procedure Edit; override; end; RegisterPropertyEditor(TypeInfo(TFileName),nil, '',
TFileProperty = class(TStringProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure Edit; override;
end;
RegisterPropertyEditor(TypeInfo(TFileName),nil, '', TFileProperty);
我认为这可能需要更多的工作,因为我认为我需要创建一个类来注册,并以某种方式调用seldirapi例程或其他东西
感谢您提供的任何帮助我想我有工作要做,除非其他人能想出更好的办法
type
TFolderName = String;
TFolderNameProperty = class(TStringProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure Edit; override;
end;
function TFolderNameProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog]
end {GetAttributes};
procedure TFolderNameProperty.Edit;
var
Dir: String;
begin
SelectDirectory('Select a directory', '', Dir)
SetValue(Dir);
end {Edit};
procedure Register;
begin
RegisterPropertyEditor(TypeInfo(TFolderName),nil, '', TFolderNameProperty)
end;
更改属性类型的定义,如下所示:
TFolderName=type string
。这使得新的RTTI类型与内置的string
类型不同。没有它,您的属性编辑器将应用于所有string
属性,而不仅仅是声明为TFolderName
的属性。与TFileName
相比。除了@Rob所说的,您可能还想1)在使用Dir之前初始化Dir(即使它是空字符串)(这是一个好习惯),2)在盲目使用Dir设置属性之前检查调用SelectDirectory()的结果。(SelectDirectory返回一个布尔值,指示是选择了目录还是取消了对话框。)