2009-09-12 51 views
4

我正在使用的組件使用TCollection來保存指向其他組件的鏈接。當項目在設計中編輯其標籤是這個樣子:在Delphi編輯器中更改TCollectionItem的標籤

0 - TComponentLink 
1 - TComponentLink 
2 - TComponentLink 
3 - TComponentLink 

如何添加有意義的標籤(鏈接組件的名稱也許)?例如

0 - UserList 
1 - AnotherComponentName 
2 - SomethingElse 
3 - Whatever 

作爲獎勵,您能告訴我如何在組件雙擊時顯示集合編輯器嗎?

回答

5

要顯示一個有意義的名字覆蓋GetDisplayName:

function TMyCollectionItem.GetDisplayName: string; 
begin 
    Result := 'My collection item name'; 
end; 

要顯示在非可視組件被雙擊,你需要重寫TComponentEditor編輯程序集編輯器。

TMyPropertyEditor = class(TComponentEditor) 
public 
    procedure Edit; override; // <-- Display the editor here 
end; 

...並註冊編輯器:

RegisterComponentEditor(TMyCollectionComponent, TMyPropertyEditor); 
1

編輯器中顯示的名稱存儲在項目的DisplayName屬性中。嘗試設置你的代碼,當您創建鏈接設置是這樣的:

item.DisplayName := linkedItem.Name; 

要小心,不要更改顯示名稱,如果用戶已經設置它,但。這是一個主要的UI煩惱。

+3

感謝梅森,但不幸的是,它並沒有爲我工作。然而,它卻讓我想到了一個可行的答案。簡單地覆蓋TCollectionItem「GetDisplayName」函數,例如 function TMyCollectionItem.GetDisplayName:string; 開始 結果:='我的收藏品名稱'; 結束; – norgepaul 2009-09-12 14:33:48

相關問題