⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myinspector.pas

📁 类似Delphi Ide的对象查看器 可以在RUNTIME时使用
💻 PAS
字号:
unit MyInspector;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  CreateDesigner, Compinsp;

type

  TMyComponentInspector = class;
{TMyFormDesigner}
  TMyFormDesigner = class(TFormDesigner)
  private
    { Private declarations }
    FInspector: TMyComponentInspector;
    FLockFusionDesigner: Boolean;
    procedure SetInspector(const Value: TMyComponentInspector);
  protected
    { Protected declarations }
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
    procedure DoChange; override;
    procedure DoSelectionChange; override;
  published
    { Published declarations }
    property Inspector: TMyComponentInspector read FInspector write SetInspector;
  end;

{TMyComponentInspector}
  TMyComponentInspector = class(TComponentInspector)
  private
    { Private declarations }
    FDesigner: TMyFormDesigner;
    FDefaultInstance: TComponent;
    procedure SetDesigner(const Value: TMyFormDesigner);
    procedure SetDefaultInstance(const Value: TComponent);
  protected
    { Protected declarations }
    procedure Notification(AComponent: TComponent; Operation: TOperation); override;
    procedure Change(TheIndex: Integer); override;
  published
    { Published declarations }
    property Designer: TMyFormDesigner read FDesigner write SetDesigner;
    property DefaultInstance: TComponent read FDefaultInstance write SetDefaultInstance;
  public
    { Public declarations }
    procedure Update; override;
  end;

implementation

{TMyFormDesigner}
procedure TMyFormDesigner.SetInspector(const Value: TMyComponentInspector);
var
  OldInspector: TMyComponentInspector;
begin
  if FInspector<>Value then
  begin
    OldInspector:=FInspector;
    FInspector:=Value;
    if Assigned(FInspector) then FInspector.Designer:=Self
    else
      if Assigned(OldInspector) then OldInspector.Designer:=nil;
  end;
end;

procedure TMyFormDesigner.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited;
  if not (csDestroying in ComponentState) and (Operation=opRemove) and (AComponent=FInspector) then
    if csDestroying in Inspector.ComponentState then FInspector:=nil
    else Inspector:=nil;
end;

procedure TMyFormDesigner.DoChange;
begin
  inherited;
  if not SynchroLocked then
    if Assigned(FInspector) then FInspector.Update;
end;

procedure TMyFormDesigner.DoSelectionChange;
var
  i: Integer;
  C: TControl;
begin
  inherited;
  FLockFusionDesigner:=True;
  try
    if not SynchroLocked then
      if Assigned(FInspector) then
        with FInspector,Self do
        begin
          case ControlCount of
            0: Instance:=DefaultInstance;
            1: Instance:=Component;
          else
            for i:=0 to Pred(ControlCount) do
              if IndexOfInstance(Controls[i])=-1 then AddInstance(Controls[i]);
            if InstanceCount>1 then DeleteInstance(DefaultInstance);
            i:=0;
            while i<InstanceCount do
            begin
              if Instances[i] is TControl then C:=TControl(Instances[i])
              else C:=FindComponentContainer(Instances[i]);
              if ControlIndex(C)=-1 then DeleteInstance(Instances[i])
              else Inc(i);
            end;
          end;
        end;
  finally
    FLockFusionDesigner:=False;
  end;
end;

{TMyComponentInspector}
procedure TMyComponentInspector.SetDesigner(const Value: TMyFormDesigner);
var
  OldDesigner: TMyFormDesigner;
begin
  if FDesigner<>Value then
  begin
    OldDesigner:=FDesigner;
    FDesigner:=Value;
    if Assigned(FDesigner) then FDesigner.Inspector:=Self
    else
      if Assigned(OldDesigner) then OldDesigner.Inspector:=nil;
    if not Assigned(FDesigner) then Instance:=FDefaultInstance;
  end;
end;

procedure TMyComponentInspector.SetDefaultInstance(const Value: TComponent);
begin
  if FDefaultInstance<>Value then
  begin
    FDefaultInstance:=Value;
    if not Assigned(Instance) then Instance:=FDefaultInstance;
  end;
end;

procedure TMyComponentInspector.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited;
  if not (csDestroying in ComponentState) and (Operation=opRemove) and (AComponent=FDesigner) then
    if csDestroying in Designer.ComponentState then FDesigner:=nil
    else Designer:=nil;
end;

procedure TMyComponentInspector.Change(TheIndex: Integer);
begin
  inherited;
  if Assigned(FDesigner) then FDesigner.Update;
end;

procedure TMyComponentInspector.Update;
begin
  inherited;
  if Assigned(FDesigner) then
    with FDesigner do
      if not FLockFusionDesigner then
      begin
        SynchroLock;
        Lock;
        try
          case InstanceCount of
            0: Control:=nil;
            1:
              if Instance<>Control then
                if Instance is TControl then Control:=TControl(Instance)
                else Component:=Instance;
          end;
        finally
          SynchroUnlock;
          Unlock;
        end;
      end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -