您现在的位置:首页 >> VCL >> VCL >> 内容

如何将一个字符串映射为一个Delphi控件属性名

时间:2011/9/3 16:24:39 点击:

  核心提示:usesTypInfo; functionTForm1.SetControlProp(ComStr,value:string):boolean; varComName,ComProp:string;...

uses TypInfo;

function TForm1.SetControlProp(ComStr, value: string): boolean;
var ComName, ComProp: string;
    i: integer;
  Loop: Integer;
  PropInfo: PPropInfo;
  cp: TComponent;
begin
  i := Pos('.', ComStr);
  if i > 0 then
  begin
    ComName := copy(ComStr, 1, i-1);
    ComProp := Copy(Comstr, i+1, 1000);
    cp := FindComponent(ComName);
    PropInfo := GetPropInfo(cp.ClassInfo, ComProp);
    if Assigned(PropInfo) then
      SetStrProp(cp, PropInfo, value);
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
 SetControlProp('button1.caption', 'test'); 

end;

作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
本类推荐
  • 没有
本类固顶
  • 没有
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号