自定义一个数组吧 const BoolToStr: array[Boolean] of String = ('错', '对'); ... begin ShowMessage(BoolToStr[1+1=2]); end;
自己定义: function booltostr(ib:boolean):string; begin if ib then result:=‘true’ else result:=‘false’ end;function strtobool(istr:string):boolean; begin if istr=true then result:=true else result:=false; end;
const
BoolToStr: array[Boolean] of String = ('错', '对');
...
begin
ShowMessage(BoolToStr[1+1=2]);
end;
function booltostr(ib:boolean):string;
begin
if ib then result:=‘true’
else result:=‘false’
end;function strtobool(istr:string):boolean;
begin
if istr=true then result:=true
else result:=false;
end;
Function BoolToStr(B: Boolean; UseBoolStrs: Boolean = False): string;
例如:
edit1.txt:=Booltostr(3<4); //文本框中显示的是'0'
edit1.txt:=Booltostr(true); //文本框中显示的是'-1'
edit1.txt:=Booltostr(false,true); //文本框中显示的是'False'
edit1.txt:=Booltostr(2=3-1,true); //文本框中显示的是'True'
begin
if Bool then
Result := 'True'
else
Result := 'False';
end;