zoukankan      html  css  js  c++  java
  • 一个没有了解透的简单函数: BoolToStr

    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 单元下的公用函数目录

  • 相关阅读:
    html+css动态篇
    html+css定位篇
    首页的css
    display详细说明
    html+css 布局篇
    html+css杂记
    JS与ES的关系
    H5本地存储
    JavaScript面向对象
    JavaScript执行上下文
  • 原文地址:https://www.cnblogs.com/del/p/1198091.html
Copyright © 2011-2022 走看看