您的位置:首页 > 编程语言 > Delphi

将一个字符串映射为一个Delphi页面控件属性名

2010-08-27 14:19 351 查看
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');   //設置button1的caption   為   test
end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐