Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12470743
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类: 数据库开发技术

2011-05-10 22:03:23

  1. unit Unit1;

  2. interface

  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls;

  6. type
  7.   TForm1 = class(TForm)
  8.     Button1: TButton;
  9.     Button2: TButton;
  10.     procedure Button1Click(Sender: TObject);
  11.     procedure Button2Click(Sender: TObject);
  12.   end;

  13. var
  14.   Form1: TForm1;

  15. implementation

  16. {$R *.dfm}

  17. //以前不知道 BoolToStr 还有一个默认参数

  18. procedure TForm1.Button1Click(Sender: TObject);
  19. var
  20.   b: Boolean;
  21.   s: string;
  22. begin
  23.   b := True;
  24.   s := BoolToStr(b);
  25.   ShowMessage(s); {-1}

  26.   b := False;
  27.   s := BoolToStr(b);
  28.   ShowMessage(s); {0}

  29.   b := True;
  30.   s := BoolToStr(b, True);
  31.   ShowMessage(s); {True}

  32.   b := False;
  33.   s := BoolToStr(b, True);
  34.   ShowMessage(s); {False}
  35. end;

  36. //以前还曾得意的这样用过, 笑话了.

  37. procedure TForm1.Button2Click(Sender: TObject);
  38. const
  39.   b2s: array[Boolean] of string = ('False', 'True');
  40. var
  41.   b: Boolean;
  42.   s: string;
  43. begin
  44.   b := True;
  45.   s := b2s[b];
  46.   ShowMessage(s); {True}

  47.   b := not b;
  48.   s := b2s[b];
  49.   ShowMessage(s); {False}
  50. end;

  51. end.
阅读(2333) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~