pename.pas

来自「Delphi高级开发指南是开发程序的好帮手」· PAS 代码 · 共 69 行

PAS
69
字号
unit PeName;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages,
  Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, DsgnIntf;

type
  TNameProperty = class (TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure Edit; override;
  end;

procedure Register;

implementation

uses
  PeFName;

{property editor methods}

function TNameProperty.GetAttributes:
  TPropertyAttributes;
begin
  Result := [paDialog];
end;

procedure TNameProperty.Edit;
var
  PeForm: TNameForm;
  TheComponent: TComponent;
  TheForm: TForm;
  I: Integer;
begin
  PeForm := TNameForm.Create (Application);
  try
    PeForm.Edit1.Text := GetValue;
    // fill the listboxes
    TheComponent := GetComponent (0) as TComponent;
    if TheComponent is TForm then
      TheForm := TForm (TheComponent)
    else
      TheForm := (TheComponent.Owner) as TForm;
    for I := 0 to TheForm.ComponentCount - 1 do
    begin
      PeForm.ListAll.Items.Add (TheForm.Components[I].Name);
      if TheForm.Components[I] is TheComponent.ClassType then
        PeForm.ListSame.Items.Add (TheForm.Components[I].Name);
    end;
    if PeForm.ShowModal = mrOK then
      SetValue (PeForm.Edit1.Text);
  finally
    PeForm.Free;
  end;
end;

procedure Register;
begin
  RegisterPropertyEditor (TypeInfo(TComponentName),
    TComponent, 'Name', TNameProperty);
end;

end.

⌨️ 快捷键说明

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