设置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;

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2021-11-26
  • 2021-08-21
猜你喜欢
  • 2022-12-23
  • 2021-08-11
  • 2022-01-27
  • 2021-08-25
  • 2022-12-23
  • 2021-11-30
  • 2021-10-15
相关资源
相似解决方案