H
huizhang
Unregistered / Unconfirmed
GUEST, unregistred user!
如果只是处理"Enable"之类简单的语句的话是很容易实现的,首先从语句中找到控件的Name,然后找出相应的属性以及其值.
procedure TForm1.SetComponentValue(const Expression: string);
const
PropertyNames: Array [0..3] of String = (
'Enabled','Visble','Width','Height');
var
CName, RestStr, ProName, ValStr: string;
MarkPos, i, Index: integer;
AControl: TControl; AComponent: TComponent;
begin
MarkPos := Pos('.',Expression);
CName := Copy(Expression, 1, MarkPos-1);
AComponent := FindComponent(CName);
if not (AComponent is TControl) then
exit;
AControl := AComponent as TControl;
RestStr := Copy(Expression, MarkPos+1,255);
MarkPos := Pos(':=',RestStr);
ProStr := Copy(RestStr,1,MarkPos-1);
RestStr := Copy(RestStr, MarkPos+2,255);
ValStr := Copy(RestStr,1,255);
index := -1;
for i := 0 to 4 do
if CompareText(ProStr, PropertyNames) = 0 then
begin
index := i;
Break;
end;
case Index of
0: AControl.Enabled := CompareText(ValStr,'True') = 0;
1: AControl.Vasible := CompareText(ValStr,'True') = 0;
2: AControl.Width := Val(ValStr);
3: AControl.Height := Val(ValStr);
end;
end;
想要更好的翻译执行的Script,可以去Delphi 32bit深度历险下载一个RALib回来看
看,里面有一个功能不错的Delphi Scripter可以翻译执行Delphi的函数,类...
procedure TForm1.SetComponentValue(const Expression: string);
const
PropertyNames: Array [0..3] of String = (
'Enabled','Visble','Width','Height');
var
CName, RestStr, ProName, ValStr: string;
MarkPos, i, Index: integer;
AControl: TControl; AComponent: TComponent;
begin
MarkPos := Pos('.',Expression);
CName := Copy(Expression, 1, MarkPos-1);
AComponent := FindComponent(CName);
if not (AComponent is TControl) then
exit;
AControl := AComponent as TControl;
RestStr := Copy(Expression, MarkPos+1,255);
MarkPos := Pos(':=',RestStr);
ProStr := Copy(RestStr,1,MarkPos-1);
RestStr := Copy(RestStr, MarkPos+2,255);
ValStr := Copy(RestStr,1,255);
index := -1;
for i := 0 to 4 do
if CompareText(ProStr, PropertyNames) = 0 then
begin
index := i;
Break;
end;
case Index of
0: AControl.Enabled := CompareText(ValStr,'True') = 0;
1: AControl.Vasible := CompareText(ValStr,'True') = 0;
2: AControl.Width := Val(ValStr);
3: AControl.Height := Val(ValStr);
end;
end;
想要更好的翻译执行的Script,可以去Delphi 32bit深度历险下载一个RALib回来看
看,里面有一个功能不错的Delphi Scripter可以翻译执行Delphi的函数,类...