如何作出下拉列表的属性?(100分)

  • 主题发起人 主题发起人 pdj
  • 开始时间 开始时间
P

pdj

Unregistered / Unconfirmed
GUEST, unregistred user!
放一个控件在窗体上,获得窗体的所有控件名
显示在属性列表中。这种属性是何种类型。Strings?
 
建议你看一下TObject类中的类方法。
 
for i:=0 to form form.components.count-1 do
begin
combobox1.items.add(form.components.name)
end;
 
最简单的
声明一
FComponentList: TComponent;
然后published部分
property ComponentList: TComponent read FComponentList write FComponentList;

不过有点骗人,呵呵
 
获得窗体的所有控件名 == >很容易,要动态的显示在属性列表中,我也想知道.
不过咳以放在TstringList ,嘿嘿感觉不是很爽.以下是代码;

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Example1: TExample;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
Example1. Active := true;
end;

end.


 
同以antic_ant
 
不好意思,刚才代码贴错了:

unit Component1;

interface

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

type
ArryStr = array[0..10] of String ;
type
TExample = class(TComponent)
private
{ Private declarations }
FActive :Boolean ;
FStringList :TStringList ;
procedure SetActive(value :boolean);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent);override;
destructor Destroy;
published
{ Published declarations }
property Active :Boolean read Factive write SetActive ;
property StrList:TStringList read FStringList ;
end;
procedure Register;

implementation

constructor TExample.Create(AOwner: TComponent);
begin
inherited ;
FStringList := TStringList .Create ;
SetActive (Factive );
end;

destructor TExample.Destroy ;
begin
FStringList .Free ;
inherited;
end;

procedure TExample. SetActive(value :boolean);
var
i:Byte ;
begin
if Factive <> value then
begin
if value = true then
for i:= 0 to ( Owner as TForm ).ComponentCount -1 do
begin
FStringList .Add ( ( Owner as TForm ).Components .ClassName );
end
else
FStringList .Clear ;
end;
Factive := value ;
end;

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

end.
 
下拉列表??

可以这样啊:

TXXXXX=(a,b,c,d,e);

声明:
Fzzz:TXXXXX;


Property zzz:TXXXXX read Fzzz write Fzzz;

我就是这样作的。
 
多人接受答案了。
 
后退
顶部