Search code examples
delphicomponentsdelphi-2010custom-componentpropertyeditor

How to create a Folder (Directory) property editor for my component?


Delphi 2010

How to create a Folder (Directory) property editor for my component?

I was able to easily create one for a FileName property using:

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

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

I think it may take alittle more work, as i think i need to create a class to register, and somehow call selDir api routine or something

thanks for any help you may offer


Solution

  • I think i got something to work, unless someone else can come up with something better

    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;