我要在程序中判断
 try
  bool1 := strtobool(Edit1.text)
 except
  bool1 := false;
 end
..
当Edit1.text 为'True','TRUE','true'都会产生异常,只用Edit1.text为数字时是正常的,
而data.FieldByName('布尔字段').asstring返回的是'True',Delphi应该认识'True'的
这是为什么?

解决方案 »

  1.   

    StrToBool functionConverts a string to a Boolean value.UnitSysUtilsCategorytype conversion routinesDelphi syntax:function StrToBool(const S: string): Boolean;C++ syntax:extern PACKAGE bool __fastcall StrToBool(const AnsiString S);DescriptionStrToBool converts the string specified by S to a Boolean. If S can be converted to a number, StrToBool returns false if that number is 0, true otherwise. If S can抰 be converted to a number, StrToBool returns true if S is any of the strings listed in TrueBoolStrs (or differs from one only by case) and false if it is any of the strings listed in FalseBoolStrs (or differs from one only by case). If S is not a number and not one of the strings listed in TrueBoolStrs or FalseBoolStrs, StrToBool raises an EConvertError exception.Note: If you do not assign a value to TrueBoolStrs, it is treated as if it contains the single string TRUE? Similarly, if you do not assign a value to FalseBoolStrs, it is treated as if it contains the single string FALSE?
      

  2.   

    错误代码就是Edit1.text不是合法的BOOL参数,实际上Edit1输入'TRUE','True'都不行.
    帮助信息明确提示不指定TrueBoolStrs缺省认为'TRUE'是合法的BOOL参数,这是不是Delphi的BUG?
      

  3.   

    只能是'0','1'才可以使用StrToBool()吧
      

  4.   

    StrToBool converts the string specified by S to a boolean. If S can be converted to a number, StrToBool returns False if that number is 0, True otherwise. If S can抰 be converted to a number, StrToBool returns True if S is any of the strings listed in TrueBoolStrs (or differs from one only by case) and False if it is any of the strings listed in FalseBoolStrs (or differs from one only by case). If S is not a number and not one of the strings listed in TrueBoolStrs or FalseBoolStrs, StrToBool raises an EConvertError exception.
      

  5.   

    兄弟,E文上说的我明白,实际情况不是这样,希望你试验一下.
    我现在的方法是自己写了一个strtobool的函数