--------------------------------------------------
var
  I1, I2: Integer;
  b: Boolean;
  wb: WordBool;
  lb: LongBool;
begin
  I1 := $FF00;
  b := I1 <> 0;       //b = ?
  b := Boolean(I1);   //b = ?
  b := WordBool(I1);  //b = ?
  b := LongBool(I1);  //b = ?  I2 := $FFFF0000;
  lb := LongBool(I2); //lb = ?
  wb := WordBool(I2); //wb = ?
  wb := WordBool(lb); //wb = ?
end;
原因:结论:---------------------------------------------------请填写上面问号的值,并写出原因和结论,答对有奖哦!!!

解决方案 »

  1.   

    The four predefined Boolean types are Boolean, ByteBool, WordBool, and LongBool. Boolean is the preferred type. The others exist to provide compatibility with other languages and operating system libraries.A Boolean variable occupies one byte of memory, a ByteBool variable also occupies one byte, a WordBool variable occupies two bytes (one word), and a LongBool variable occupies four bytes (two words).Boolean values are denoted by the predefined constants True and False. The following relationships hold.Boolean ByteBool, WordBool, LongBool
    False < True False <> True
    Ord(False) = 0 Ord(False) = 0
    Ord(True) = 1 Ord(True) <> 0
    Succ(False) = True Succ(False) = True
    Pred(True) = False Pred(False) = True
    A value of type ByteBool, LongBool, or WordBool is considered True when its ordinality is nonzero. If such a value appears in a context where a Boolean is expected, the compiler automatically converts any value of nonzero ordinality to True.
    The previous res refer to the ordinality of Boolean values, not to the values themselves. In Delphi, Boolean expressions cannot be equated with integers or reals. Hence, if X is an integer variable, the statementif X then ...;generates a compilation error. Casting the variable to a Boolean type is unreliable, but each of the following alternatives will work.if X <> 0 then ...;        { use longer expression that returns Boolean value }
    var OK: Boolean            { use Boolean variable }
     ...
    if X <> 0 then OK := True;
    if OK then ...;
      

  2.   

    1字节 Boolean,ByteBool 
    2字节 WordBool 
    4字节 BOOL,LongBool
      

  3.   

    ...我使用布尔值只用Boolean其他一概不用...估计没啥帮助啦
      

  4.   

    当你与Windows的API打交道时,就大有用途了。
    大家似乎没有我的意思,我是想让大家填写各个表达式计算出来的布尔值。
      

  5.   

    厄...怎么填写?闭卷还是开卷?闭卷的话答不上来...我脑子犯糊涂,肯定会算错开卷的话...懒得打开delphi...哈哈应该是由于字节数不同的类型相互转换,导致了结果变化本来想兑奖的...关注一下期待答案
      

  6.   

    var
      I1, I2: Integer;
      b: Boolean;
      wb: WordBool;
      lb: LongBool;
    begin
      I1 := $FF00;
      b := I1 <> 0;       //b = true
      b := Boolean(I1);   //b = false
      b := WordBool(I1);  //b = true
      b := LongBool(I1);  //b = true  I2 := $FFFF0000;
      lb := LongBool(I2); //lb = true
      wb := WordBool(I2); //wb = false
      wb := WordBool(lb); //wb = true
    end;在电脑上试了一下。
    我这么理解:
    1.强制类型转换,字节数不等,将截断高字节
    如:
     I1 := $FF00;
      b := Boolean(I1);   //b = false
    截断后Boolean(I1);值为$00;  I2 := $FFFF0000;
     wb := WordBool(I2); //wb = false
    截断后WordBool(I2); 值为$0000;
    2.布尔型的值
      I2 := $FFFF0000;
      lb := LongBool(I2); 
    用  showmessage(inttostr(integer(lb)));可以看到其值仍为$FFFF0000;
    3.字节数不同的布尔型之间的强制转换
    应该是为了保证语意逻辑上的一致,换句话说,一个true值的布尔型,不管你转成哪种布尔型,它都应该是true。而按上面两条,将有可能破坏这个逻辑。因此,在转换后采用了特定的值,即0,1或0,-1
    0,1用于boolean型
    0,-1用于WordBool及LongBool
    因此,
      I2 := $FFFF0000;
      lb := LongBool(I2);
      wb := WordBool(lb); //LongBool强制转换成WordBool,其值为-1
      

  7.   

    zaza_bbface:  100分
    chijingde(AD): 顶得这么辛苦:20分 ^_~
      

  8.   

    所以,如果我们用SendMessage的时候,如果返回值是BOOL值,则要特别小心了。最好用BOOL去强制转换,如果用Boolean,则非常不安全。