原问题http://topic.csdn.net/u/20090325/15/f99c7c82-050b-4e34-9275-219b91d52f1d.html今天查资料的过程中突然想起这个问题,也看了大家的解答,明白了很多,但是大家忽略了一个问题。
让我来阐述下:
编译指令{$B-} {$B+}这是一对编译指令,布尔评估。
{$B-}: 关闭布尔评估(编译器默认值)
{$B+}: 打开布尔评估
在关闭状态下 A or B or C 这样的条件时,如果A为true则不执行B,C语句
A and B and C 这样的条件时,如果A为false则不执行B,C语句
打开的状态下,无论怎样都必须执行B,C
请大家看下面的注释部分,红色为我添加的内容
引用121楼npkaida 代码如下:
Delphi(Pascal) code
procedure TForm1.Button1Click(Sender: TObject);
var
s: string;
begin
if GetTrue or GetValue1(s) then //因为 GetValue1(s) 返回值是 Variant,
//GetTrue 必须和 GetValue1(s) 返回值进行 or 运算
//才能判断是否执行 ShowMessage('Hello ' + s);
//也就是说会执行 GetValue1(s), 因此 s = 'World'
//这里的解释我依旧不是很明白,我猜测如果GetValue1(s) 返回值是Variant,那么编译器怕漏掉需要执行的代码就必须执行从而忽略编译指令{$B-}
ShowMessage('Hello ' + s); //Hello Word
end;procedure TForm1.Button2Click(Sender: TObject);
var
s: string;
begin
{$B+}//加上这句话后show出来的就是Hello word了
if GetTrue or GetValue2(s) then //因为 GetValue2(s) 返回值是 Boolean,
//所以程序先判断 GetTrue 是否返回 true
//如果是 true 就不执行 GetValue2(s)
//直接运行 ShowMessage('Hello ' + s);
//也就是说,因GetValue2(s)没有运行, 所以
//s 为空。
ShowMessage('Hello ' + s); // Hello
{$B-}
end;如果进行以下修改:
procedure TForm1.Button1Click(Sender: TObject);
var
s: string;
begin
if GetTrue or boolean(GetValue1(s)) then //因为强制将 GetValue1(s) 返回值设为 boolean,
//所以程序先判断 GetTrue 是否返回 true
//如果是 true 就不执行 GetValue2(s)
//直接运行 ShowMessage('Hello ' + s);
//也就是说,因GetValue2(s)没有运行, 所以
//s 为空。
ShowMessage('Hello ' + s); // Hello
end;
让我来阐述下:
编译指令{$B-} {$B+}这是一对编译指令,布尔评估。
{$B-}: 关闭布尔评估(编译器默认值)
{$B+}: 打开布尔评估
在关闭状态下 A or B or C 这样的条件时,如果A为true则不执行B,C语句
A and B and C 这样的条件时,如果A为false则不执行B,C语句
打开的状态下,无论怎样都必须执行B,C
请大家看下面的注释部分,红色为我添加的内容
引用121楼npkaida 代码如下:
Delphi(Pascal) code
procedure TForm1.Button1Click(Sender: TObject);
var
s: string;
begin
if GetTrue or GetValue1(s) then //因为 GetValue1(s) 返回值是 Variant,
//GetTrue 必须和 GetValue1(s) 返回值进行 or 运算
//才能判断是否执行 ShowMessage('Hello ' + s);
//也就是说会执行 GetValue1(s), 因此 s = 'World'
//这里的解释我依旧不是很明白,我猜测如果GetValue1(s) 返回值是Variant,那么编译器怕漏掉需要执行的代码就必须执行从而忽略编译指令{$B-}
ShowMessage('Hello ' + s); //Hello Word
end;procedure TForm1.Button2Click(Sender: TObject);
var
s: string;
begin
{$B+}//加上这句话后show出来的就是Hello word了
if GetTrue or GetValue2(s) then //因为 GetValue2(s) 返回值是 Boolean,
//所以程序先判断 GetTrue 是否返回 true
//如果是 true 就不执行 GetValue2(s)
//直接运行 ShowMessage('Hello ' + s);
//也就是说,因GetValue2(s)没有运行, 所以
//s 为空。
ShowMessage('Hello ' + s); // Hello
{$B-}
end;如果进行以下修改:
procedure TForm1.Button1Click(Sender: TObject);
var
s: string;
begin
if GetTrue or boolean(GetValue1(s)) then //因为强制将 GetValue1(s) 返回值设为 boolean,
//所以程序先判断 GetTrue 是否返回 true
//如果是 true 就不执行 GetValue2(s)
//直接运行 ShowMessage('Hello ' + s);
//也就是说,因GetValue2(s)没有运行, 所以
//s 为空。
ShowMessage('Hello ' + s); // Hello
end;
解决方案 »
- 一个事件,能不能保存到流中,然后从流中读出并恢复?
- 刚学三层,有很多问题问题的向前辈请教!
- 怎样编写服务器端用SQL的C/S程序?用何种方式连接数据库最好?谢谢!!!
- 如何让edit输入框里边的输入内容右对齐呀???
- 来分析下这段代码,关于ADO内存增长问题
- 如何让两个CheckListBox内容同步?
- 数据库SQL问题,很菜,大虾们请帮忙
- 怎样设置FileListBox1的路径
- 请教:我的这两个程序相差不大,为什么一个可以,一个不可以呢?
- 把记录的字段写入Excel里?
- 关于IShellFolder.GetUIObjectOf中传入多个PIDL获取IContextMenu的问题
- 关于ListView的问题!
好比你弄清了C的表达式 a+=a-=a*a 的运算步骤跟你能否写出好程序没什么关系