如何判断Form中的一个控件是否具有某个属性? 找免费的销售管理软件
例如:判断Edit1是否具有Text属性,判断Label1是否具有Text属性,等等
2楼: 遍历最起码你要知道哪个控件属于哪个类啊 如管家婆库存管理软件
3楼: TWinControl或者TControl类
4楼: l类类型就知道有没有属性
5楼: 具体例子:我知道Label1没有Text属性,但是怎样用代码判断Label1是否有Text属性?
6楼: 参考
http://www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm
进销存软件版7楼: Count := GetTypeData(Sender.ClassInfo)^.PropCount;
if Count > 0 then
begin
// 得到属性数
GetMem(PropList, Count * SizeOf(PPropList));
try
// ?得到属性
GetPropInfos(Sender.ClassInfo, PropList);
frmObject.insp.RowCount:=count;
frmObject.event.RowCount:=count;
j:=0;
K:=0;
for I := 0 to Count - 1 do
begin
PropInfo := PropList^[I];
case PropInfo.PropType^.kind of
tkInteger,
tkEnumeration :
frmObject.insp.cells[1,j]:= inttostr(getordProp(Sender,PropInfo));
tkString,
tkLString,
tkWString :
frmObject.insp.cells[1,j]:= getstrProp(Sender,PropInfo);
tkFloat :
frmObject.insp.cells[1,j]:=FloattoStr(GetFloatProp(Sender,PropInfo));
tkMethod :
frmObject.event.cells[1,k]:=''Event'';
else
frmObject.insp.cells[1,i]:=''TYPE''+inttostr(ord(PropInfo.PropType^.kind));
end;
if PropInfo.PropType^.kind=tkMethod then
begin
frmObject.event.cells[0,k]:=PropInfo.Name;
k:=k+1
end
else
begin
frmObject.insp.cells[0,j]:=PropInfo.Name;
j:=j+1;
end;
end;
frmObject.insp.RowCount:=j;
frmObject.event.RowCount:=k;
finally
FreeMem(PropList, Count * SizeOf(PPropList));
end;
end;
8楼: uses typinfo
function IsProperty(
const AObject : TObject;
const APropName : string
):Boolean;
begin
Result := Assigned(GetPropInfo(AObject.ClassInfo,APropName));
end;
9楼: 哈哈,又有分
try
Label1.text := '''';
showmessage(''有该属性!'')
except
showmessage(''没有该属性!'')
end;
10楼: >>哈哈,又有分
>>try
>>Label1.text := '''';
>>showmessage(''有该属性!'')
>>except
>>showmessage(''没有该属性!'')
>>end;
这样也可以啊!晕哦!
11楼: try
Label1.text := '''';
showmessage(''有该属性!'')
except
showmessage(''没有该属性!'')
end;
这能编译通过?
12楼: 感谢 如免费的销售管理软件
13楼: 给分,谢谢。