您的位置:首页 > 其它

一个没有了解透的简单函数: BoolToStr

2008-05-15 12:27 423 查看
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 单元下的公用函数目录
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐