procedure TForm1.Button1Click(Sender: TObject);
var a,b :integer;
var s:string;
begin
a:=1;
b:=2;
s:='a<b';
if a<b then
begin
showmessage('ok');
end;
end;
end.
if 后面是条件,我想用S来替换。(即把'a<b'改为我最先设定的条件字符串s)怎么做???
...全文
158166打赏收藏
问题感觉不容易搞定,高手们进来看看。
procedure TForm1.Button1Click(Sender: TObject); var a,b :integer; var s:string; begin a:=1; b:=2; s:='a<b'; if a<b then begin showmessage('ok'); end; end; end. if 后面是条件,我想用S来替换。(即把'a<b'改为我最先设定的条件字符串s)怎么做???
可以用脚本来解决这个问题
把S定义为布尔型,然后用脚本控件对表达式字符串s1进行运算,将结果赋值给S即可
注意,如果不能使用请安装脚本控件,在微软的网站上有下载
var
scTest:Variant;
s1:string; //要判断的表达式
s:Boolean;
begin
scTest := CreateOleObject('ScriptControl');
scTest.Language := 'VBScript';
scTest.SitehWnd := self.Handle;
scTest.Timeout:= -1;
s := scTest.Eval(s1);
if s then
showmessage('真')
else
showmessage('假');
end;