unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} //以前不知道 BoolToStr 还有一个默认参数 procedure TForm1.Button1Click(Sender: TObject); var b: Boolean; s: string; begin b := True; s := BoolToStr(b); ShowMessage(s); {-1} b := False; s := BoolToStr(b); ShowMessage(s); {0} b := True; s := BoolToStr(b, True); ShowMessage(s); {True} b := False; s := BoolToStr(b, True); ShowMessage(s); {False} end; //以前还曾得意的这样用过, 笑话了. procedure TForm1.Button2Click(Sender: TObject); const b2s: array[Boolean] of string = ('False', 'True'); var b: Boolean; s: string; begin b := True; s := b2s[b]; ShowMessage(s); {True} b := not b; s := b2s[b]; ShowMessage(s); {False} end; end.SysUtils 单元下的公用函数目录
转载于:https://www.cnblogs.com/del/archive/2008/05/15/1198091.html