2

德尔福 2010

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

我可以使用以下方法轻松地为 FileName 属性创建一个:

TFileProperty = class(TStringProperty)  
public  
  function GetAttributes: TPropertyAttributes; override;  
  procedure Edit; override;  
end;  

RegisterPropertyEditor(TypeInfo(TFileName),nil, '', TFileProperty);  

我认为这可能需要更多的工作,因为我认为我需要创建一个类来注册,并以某种方式调用 selDir api 例程或其他东西

感谢您提供的任何帮助

4

1 回答 1

3

我想我有一些工作要做,除非其他人能想出更好的东西

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;  
于 2010-12-29T03:10:41.860 回答