[英]Delphi XE4 IDE, how to always hide the bottom panes of the Object Inspector
下面的XE4代碼顯示了如何隱藏要刪除的項目:它們是THotCommands
和TDescriptionPane
類的實例。
更新此答案的原始版本需要一個包含加載項表格和刷新對象檢查器以隱藏兩個不需要的項目的按鈕的程序包。 在下面的代碼中,我完全刪除了表單,並且項目的隱藏現在應該是全自動的。 為此,我用DesignNotification
對象替換了以前的IDENotifier,並使用其SelectionChanged
事件來調用隱藏THotCommands
和TDescriptionPane
控件的代碼。 TDesignNotification
在IDesignNotification
中實現IDesignNotification
接口
另一個對於使隱藏過程自動運行至關重要的細節是將THotCommands
和TDescriptionPane
控件的Height
設置為0,因為在OI中選擇了組件后,IDE似乎將其Visible
屬性重置為True
改變。 幸運的是,無論執行什么代碼,都不會將其Heights重置為非零值。
顯然,要使用它,請將包含代碼的單元添加到包(.Dpk)文件中,然后在IDE中編譯並安裝該包。
碼:
interface
uses
[...]ToolsApi, DesignIntf;
type
TDesignNotification = class(TInterfacedObject, IDesignNotification)
procedure ItemDeleted(const ADesigner: IDesigner; AItem: TPersistent);
procedure ItemInserted(const ADesigner: IDesigner; AItem: TPersistent);
procedure ItemsModified(const ADesigner: IDesigner);
procedure SelectionChanged(const ADesigner: IDesigner;
const ASelection: IDesignerSelections);
procedure DesignerOpened(const ADesigner: IDesigner; AResurrecting: Boolean);
procedure DesignerClosed(const ADesigner: IDesigner; AGoingDormant: Boolean);
constructor Create;
destructor Destroy; override;
private
procedure HideItems;
procedure HideFormItems(Form: TForm);
end;
var
DesignNotification : TDesignNotification;
implementation
procedure SetUp;
begin
DesignNotification := TDesignNotification.Create;
RegisterDesignNotification(DesignNotification);
end;
constructor TDesignNotification.Create;
begin
inherited Create;
end;
procedure TDesignNotification.DesignerClosed(const ADesigner: IDesigner;
AGoingDormant: Boolean);
begin
end;
procedure TDesignNotification.HideFormItems(Form : TForm);
var
j,
l : Integer;
Panel : TPanel;
C : TComponent;
HideCount : Integer;
procedure HideControl(AControl : TControl);
begin
AControl.Height := 0; // This is necessary because the IDE seems to reset
// Visible to True when the Object Inspector is refreshed.
AControl.Visible := False;
end;
begin
HideCount := 0;
for j := 0 to Form.ComponentCount - 1 do begin
C := Form.Components[j];
if C is TPanel then begin
Panel := TPanel(C);
for l := 0 to Panel.ControlCount - 1 do begin
if CompareText(Panel.Controls[l].ClassName, 'TDescriptionPane') = 0 then begin
HideControl(Panel.Controls[l]);
Inc(HideCount);
end
else
if CompareText(Panel.Controls[l].ClassName, 'THotCommands') = 0 then begin
HideControl(Panel.Controls[l]);
Inc(HideCount);
end;
if HideCount >= 2 then // we're done
exit;
end;
end;
end;
end;
procedure TDesignNotification.HideItems;
var
i : Integer;
Form : TForm;
begin
for i := 0 to Screen.FormCount - 1 do begin
Form := Screen.Forms[i];
if CompareText(Form.ClassName, 'TPropertyInspector') = 0 then begin
HideFormItems(Form);
Break;
end;
end;
end;
procedure TDesignNotification.DesignerOpened(const ADesigner: IDesigner;
AResurrecting: Boolean);
begin
end;
var
DestroyCount : Integer;
destructor TDesignNotification.Destroy;
begin
Inc(DestroyCount);
inherited;
end;
procedure TDesignNotification.ItemDeleted(const ADesigner: IDesigner;
AItem: TPersistent);
begin
end;
procedure TDesignNotification.ItemInserted(const ADesigner: IDesigner;
AItem: TPersistent);
begin
end;
procedure TDesignNotification.ItemsModified(const ADesigner: IDesigner);
begin
end;
procedure TDesignNotification.SelectionChanged(const ADesigner: IDesigner;
const ASelection: IDesignerSelections);
var
C : TComponent;
begin
// This can get called with ADesigner = Nil
if ADesigner = Nil then
exit;
C := ADesigner.Root;
if C <> Nil then begin
HideItems;
end
end;
initialization
SetUp;
finalization
if DesignNotification <> Nil then begin
UnRegisterDesignNotification(DesignNotification);
end;
end.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.