设置font size,遍历所有控件,有的控件没有font属性,所以要用GetPropInfo判断
if (GetPropInfo(cmp, "font"))
function GetObjectProperty(
const AObject : TObject;
const APropName : string
):TObject;
var
PropInfo:PPropInfo;
begin
Result := nil;
PropInfo:=GetPropInfo(AObject.ClassInfo,APropName);
if Assigned(PropInfo) and
(PropInfo^.PropType^.Kind = tkClass) then
Result := GetObjectProp(AObject,PropInfo);
end;
function SetIntegerPropertyIfExists(
const AObject : TObject;
const APropName : string;
const AValue : integer
):Boolean;
var
PropInfo:PPropInfo;
begin
PropInfo:=GetPropInfo(AObject.ClassInfo,APropName);
if Assigned(PropInfo) and
(PropInfo^.PropType^.Kind = tkInteger) then
begin
SetOrdProp(AObject,PropInfo,AValue);
Result:=True;
end else
Result:=False;
end;
//调用
procedure TFrmTest.FormCreate(Sender: TObject);
var
objTemp : TObject;
begin
objTemp := GetObjectProperty(Self,'Font');
if Assigned(objTemp) then
SetIntegerPropertyIfExists(objTemp,'Size',9);
end;