如何知道哪些控件类是否具有某一个属性(如具有Caption属性的控件有: TButton,TPanel,TCheckBox). 如我把所有具有Caption的控件类先放在一个数组内, 然后在遍历窗体上的所有控件. 如然后判断这个当前遍历的控件是否在数组内.如果在. 如果在就设置它的Caption为"Caption".(不能分开(即不能像这样 TButton(components[i]).caption :='caption',TPanel(components[i]).caption :='caption'....这样一个个强制转换. 我需求一个语句来实现. 也不能用CASE. 我需要一个通用的.不知道是不有这样的类或方法.
类似于如下代码(但代码通不过,有错,大概意思是这样)
implementation{*.res} var Class_lib: array[0..3] of TClass = (TButton,TPanel,TSpeedButton,TToolButton);
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
ObjType :TClass;
begin
for i:= componentcount-1 downto 0 do
begin
if components[i] is TObject then
begin
Objtype := Components[i].classtype;
// Listbox1.Items.Add(Tobject(Components[i]).ClassName);
for j := low(Class_lib) to High(Class_lib) do
if(class_lib[j] = Objtype) then
begin
// Listbox1.Items.Add(Tobject(Components[i]).ClassName);
Class_lib[i](Components[i] as Class_Lib).Caption := 'Caption';
end;
next; end;
end;
end;如有不明,可跟我交流. msn :[email protected], QQ :272762202
类似于如下代码(但代码通不过,有错,大概意思是这样)
implementation{*.res} var Class_lib: array[0..3] of TClass = (TButton,TPanel,TSpeedButton,TToolButton);
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
ObjType :TClass;
begin
for i:= componentcount-1 downto 0 do
begin
if components[i] is TObject then
begin
Objtype := Components[i].classtype;
// Listbox1.Items.Add(Tobject(Components[i]).ClassName);
for j := low(Class_lib) to High(Class_lib) do
if(class_lib[j] = Objtype) then
begin
// Listbox1.Items.Add(Tobject(Components[i]).ClassName);
Class_lib[i](Components[i] as Class_Lib).Caption := 'Caption';
end;
next; end;
end;
end;如有不明,可跟我交流. msn :[email protected], QQ :272762202
解决方案 »
- 看了很多想关帖子,还是不找不到方法,再求助了: DBGrid/DBGridEh picklist有没有下拉事件
- ClientDataSet中加合计字段ACTIVE设置为TRUE,DBGRID显示不出来?????
- vclskin的窗体最大化的问题。
- 急!!!如何显示!!!
- 欢迎访问一个很好的网站www.5ierp.com
- 能不能将一个DATASET中的数据成批导入到另一个DATASET
- 在Delphi中读取Oracle中Blob字段的问题,大家帮忙看一下.~~
- 可不可以动态生成dll文件!
- 一个关于字段项为空的问题!
- 西门子手机实时收发短信的程序外包欢迎参与
- 请问题一下微软开发的MSComm控件需要哪几个文件才能运行?
- 如何制作类似QQ那样的界面?
SetPropValue(Self.Components[i], 'Caption', '1234567');
end;
type
myclass = Tcontrol
endif(components[i] is tcontrol) then
Tcontrols(components[i]).caption := "caption"
.....