1.通过属性字符修改对象属性值(published )
SetPropValue(DBText1,'Color',$000080);
SetPropValue(self.DBEdit1,'BorderStyle',bsNone);
2.通过字符串访问对象属性.(published )
GetPropValue(self.DBEdit1,'BorderStyle',true);
GetPropValue(self.DBText1,'Color',true) 3.通过字符串呼叫对象方法(方法必须是published 级别的)
procedure InvokeMethod(obj: TObject; methoName: string);
type
TExec = procedure of object;
var
Routine: TMethod;
Exec: TExec;
begin
Routine.Data := Pointer(obj);
Routine.Code := obj.MethodAddress('ButtonClick');
if NOT Assigned(Routine.Code) then
Exit;
Exec := TExec(Routine);
Exec;
end; 4.通过字符串设置事件 (
ButtonClick 必须是published 级别的)procedure TForm4.Button3Click(Sender: TObject);
var
M: TMethod;
begin
M.Code := self.MethodAddress('ButtonClick');
M.Data := self;
SetMethodProp(self.Button4, 'OnClick', M);
end; 5.字符串与枚举类型的转化
var b:TBorderStyle;
b:=TBorderStyle(GetEnumValue(TypeInfo(TBorderStyle), 'bsSingle'));
//转字符号
GetEnumName(TypeInfo(TBorderStyle),Ord(bsSingle)) 6.字符创建窗口
function TShowFormClass.CreateAClass(const AClassName: string): TForm;
var
LFormClass : TFormClass;
LForm: TForm;
begin
LFormClass := TFormClass(FindClass(AClassName));
LForm := LFormClass.Create(Application);
Result := LForm;
end;
//
//创建的窗口必须先注册
initialization
begin
RegisterClasses([TAboutBox,TFormArea]);
end;
finalization
begin
UnRegisterClasses([TAboutBox,TFormArea]);
end;
// 调用
CreateAClass('TFormArea');