原问题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;