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

📄 cenvcoll.pas

📁 Delphi高级开发指南是开发程序的好帮手
💻 PAS
字号:
unit CeNvColl;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, DsgnIntf;

type
  TDdhCollect = class (TComponent)
  private
    FAllComps: Boolean;
    FComps: TStringList;
  public
    constructor Create (AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property AllComps: Boolean
      read FAllComps write FAllComps default False;
  end;

  TDdhCollectEditor = class (TComponentEditor)
  public
    function GetVerbCount: Integer; override;
    function GetVerb(Index: Integer): string; override;
    procedure ExecuteVerb(Index: Integer); override;
  end;

procedure Register;

implementation

// component

constructor TDdhCollect.Create (AOwner: TComponent);
var
  I: Integer;
begin
  // create a single instance only
  for I := 0 to AOwner.ComponentCount - 1 do
    if AOwner.Components[I] is TDdhCollect then
      raise Exception.Create (
        'Component already available in ' + AOwner.Name);
  // construction
  inherited Create (AOwner);
  FAllComps := False;
  if csDesigning in ComponentState then
    FComps := TStringList.Create
  else
    FComps := nil;
end;

destructor TDdhCollect.Destroy;
begin
  FComps.Free;
  inherited;
end;

// component editor

function TDdhCollectEditor.GetVerbCount: Integer;
var
  I: Integer;
begin
  with Component as TDdhCollect do
  begin
    if FAllComps then
      Result := Designer.Form.ComponentCount
    else
    begin
      FComps.Clear;
      for I := 0 to Designer.Form.ComponentCount - 1 do
        if not (Designer.Form.Components [I] is TControl) then
          FComps.AddObject (Designer.Form.Components [I].Name,
            Designer.Form.Components [I]);
      Result := FComps.Count;
    end;
  end; // with
end;

function TDdhCollectEditor.GetVerb (Index: Integer): string;
begin
  with Component as TDdhCollect do
    if FAllComps then
      Result := Designer.Form.Components [Index].Name
    else
      Result := FComps.Strings [Index];
end;

procedure TDdhCollectEditor.ExecuteVerb (Index: Integer);
begin
  with Component as TDdhCollect do
    if FAllComps then
      (Designer as TFormDesigner).SelectComponent (
         Designer.Form.Components [Index])
    else
      (Designer as TFormDesigner).SelectComponent (
         FComps.Objects [Index] as TComponent);
end;

procedure Register;
begin
  RegisterComponents ('DDHB', [TDdhCollect]);
  RegisterComponentEditor (TDdhCollect, TDdhCollectEditor);
end;

end.

⌨️ 快捷键说明

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