2012-01-21 19 views
6

我需要幫助來製作一個控制屬性,當你點擊它時,它會彈出一個自定義對話框,如設置。就像TPicture一樣。如何製作自定義組件屬性?

任何想法或建議?

+0

+1不知道爲什麼有人低估了一個很好的問題 –

+0

@David:不知何故,最近Delphi的所有問題都沒有任何評論,因此得不到任何評論。也許有人不明白箭頭的用途是什麼? :) –

回答

8

如果你的類被用作其他組件的屬性,要使用Object Inspector來調用你的對話框,那麼你必須實現並註冊自定義屬性編輯器,例如:

interface 

uses 
    DesignIntf, DesignEditors; 

type 
    TMyClassProperty = class(TPropertyEditor) 
    public 
    procedure Edit; override; 
    function GetAttributes: TPropertyAttributes; override; 
    end; 

procedure Register; 

implementation 

uses 
    MyClassUnit; 

procedure TMyClassProperty.Edit; 
begin 
    with TMyDialog.Create(nil) do 
    try 
    ShowModal; 
    finally 
    Free; 
    end; 
end; 

function TMyClassProperty.GetAttributes: TPropertyAttributes; 
begin 
    Result := inherited GetAttributes + [paDialog]; 
end; 

procedure Register; 
begin 
    RegisterPropertyEditor(TypeInfo(TMyClass), nil, '', TMyClassProperty); 
end; 
+0

+1我誤解了這個問題 –