Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 如何为我的组件创建文件夹(目录)属性编辑器?_Delphi_Components_Delphi 2010_Custom Component_Propertyeditor - Fatal编程技术网

Delphi 如何为我的组件创建文件夹(目录)属性编辑器?

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, '',

德尔福2010

如何为我的组件创建文件夹(目录)属性编辑器

我可以使用以下方法轻松创建一个文件名属性:

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返回一个布尔值,指示是选择了目录还是取消了对话框。)