组件已发布属性,如TFont.Name

时间:2012-11-14 10:20:35

标签: delphi components

我在下面写了一个样本组件:

unit Test;

interface

uses
  System.SysUtils, System.Classes, System.Variants, VCL.Dialogs;

type
  TTest = class(TComponent)
  private
    fName: TStringList;
    { Private declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); Override;
    destructor Destroy; override;
  published
    { Published declarations }
    property Names: TStringList read fName;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TTest]);
end;

{TTest }

constructor TTest.Create(AOwner: TComponent);
begin
  inherited;
  fName := TStringList.Create;
  for i:= 1 to 100 do
      fName.Add(IntToStr(i));
end;

destructor TTest.Destroy;
begin
  fName.Free;
  inherited;
end;

end.

现在当我在Delphi上安装它时,在Object Inspector中我有一个名为“Names”的属性,我应该双击它,然后一个对话框显示存储在Name上的TStringList项目。

我想在其他组件(如TEdit等)中创建类似Font.Name的属性,当点击Name属性,列表显示并且用户可以从中选择项目,然后将项目分配给属性并在Object Inspector中显示为属性值。

1 个答案:

答案 0 :(得分:5)

您需要为您的房产编写属性编辑器。以下是一些供您阅读的链接,因为它不是一个简单的答案: -

http://www.drbob42.com/delphi/property.htm

http://delphi.about.com/library/bluc/text/uc092501a.htm

http://www.delphicorner.f9.co.uk/articles/comps1.htm