2013-10-07 35 views
0

XE3 Prof,Win64。Delphi,按鈕編輯器,在IDE中保留默認點擊

我基於TButton創建了一個新的Button組件。

它在IDE中有一個特殊的菜單,名爲「Set Button Style」。

procedure Register; 
begin 
    RegisterComponents('SComps', [TSAButton]); 
    RegisterComponentEditor(TSAButton, TSAButtonEditor); 
end; 

procedure TSAButtonEditor.ExecuteVerb(Index: Integer); 
begin 
    Set_Style(TSAButton(Component)); 
end; 

function TSAButtonEditor.GetVerb(Index: Integer): string; 
begin 
    Result := 'Set Button Style'; 
end; 

function TSAButtonEditor.GetVerbCount: Integer; 
begin 
    Result := 1; 
end; 

該按鈕在IDE中有特殊的點擊 - 雙擊該組件會在我的代碼中生成OnClick。

當我安裝了我的編輯器菜單後,此功能丟失了,因爲IDE調用了我的功能,而不是原來的(默認代碼生成)。

如何在保存菜單的同時在我的按鈕中恢復此功能?

感謝您的每一個信息!

dd

+0

特定的Delphi版本應該在你的標籤中。由於你已經有5個標籤,你必須刪除最不相關的添加'delphi-xe3' –

+0

我不明白這意味着什麼:*在我安裝了我的編輯器菜單後,此功能丟失,因爲IDE調用我的功能,而不是原來的。* –

+0

當您點擊普通按鈕時,IDE會生成「onclick」到dfm/pas。在我安裝我的編輯器之後,IDE調用我的「設置按鈕樣式」功能。因此,「onclick」會爲我產生損失。 – durumdara

回答

0

我猜你的編輯器是從TComponentEditor繼承的? 如果是這樣,您需要調用默認的編輯功能,以便在您的編輯器ExecuteVerb函數內部生成組件的OnClick事件。 注:編輯功能在TComponentEditor類空.. 所以你需要使用IDefaultEditor接口來調用編輯功能:

第一種方法:

procedure TYourEditor.ExecuteVerb(Index: Integer); 
var 
    DefEditor: IDefaultEditor; 
begin 
    DefEditor := TDefaultEditor.Create(Component, Designer); 
    DefEditor.Edit; 
    case Index of 
    0: 
     // DoSomething !! 
     // ... 
     // ... 
    end; 
     //... 
end; 

第二種方法:

您有另一種方法:您可以從TDefaultEditor類(而不是從TComponentEditor)繼承編輯器:

TYourEditor = class(TDefaultEditor) 
    ..... 
procedure TYourEditor.ExecuteVerb(Index: Integer); 
begin 
    inherited; 
end; 

但是,如果你使用第二種方法,你將失去你的能力(只有雙擊時,其他上下文菜單纔會正常運行)。 我寧願使用第一種方法。

+0

我試着做你的第一個解決方案。第一個版本是錯誤的,因爲onclick和我的菜單也顯示。接下來,我把兩個菜單:0)OnClick 1)設置樣式對話框,我打電話編輯情況下0.很酷,工作。但是:需要我在程序結束時釋放DefEditor?我現在不確定... – durumdara

+0

@durumdara:不,您不需要釋放'DefEditor',它的一個接口,它會自動銷燬。 –

+0

謝謝,它運作良好,根據需要! :-) – durumdara