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 > then
begin
ComName := copy(ComStr, , i-);
ComProp := Copy(Comstr, i+, );
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;
http://www.cnblogs.com/kfarvid/archive/2009/10/19/1586229.html