zoukankan      html  css  js  c++  java
  • 用一个 Byte 数表示 8 个复选框的选择状态


    本例效果图:



    代码文件:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, CheckLst;
    
    type
      TForm1 = class(TForm)
        CheckListBox1: TCheckListBox;
        Button1: TButton;
        Edit1: TEdit;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure CheckListBox1Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    var
      num: Integer;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Edit1.Text := '输入一个 Byte 数';
      CheckListBox1.Align := alLeft;
      CheckListBox1.Items.CommaText := 'A,B,C,D,E,F,G,H';
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i: Integer;
    begin
      num := Lo(StrToIntDef(Edit1.Text, 0));
      Edit1.Text := IntToStr(num);
      for i := 0 to 7 do CheckListBox1.Checked[i] := 1 shl i or num = num;
      Text := IntToStr(num);
    end;
    
    procedure TForm1.CheckListBox1Click(Sender: TObject);
    var
      i: Integer;
    begin
      num := 0;
      for i := 0 to 7 do if CheckListBox1.Checked[i] then num := num or 1 shl i;
      Text := IntToStr(num);
      Edit1.Text := Text;
    end;
    
    end.
    

    窗体文件:
    object Form1: TForm1
      Left = 0
      Top = 0
      Caption = 'Form1'
      ClientHeight = 127
      ClientWidth = 231
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object CheckListBox1: TCheckListBox
        Left = 8
        Top = 8
        Width = 105
        Height = 113
        ItemHeight = 13
        TabOrder = 0
        OnClick = CheckListBox1Click
      end
      object Button1: TButton
        Left = 128
        Top = 72
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 1
        OnClick = Button1Click
      end
      object Edit1: TEdit
        Left = 119
        Top = 32
        Width = 98
        Height = 21
        TabOrder = 2
        Text = 'Edit1'
      end
    end
    

  • 相关阅读:
    Java的三个基础排序算法(其余将在以后补充)
    Review PHP设计模式之——单例模式
    Mysql忘记密码,重新设置
    PHP加解密相关函数
    http返回状态代码及含义
    符合web标准的网页下拉菜单
    解决MySQL查询不区分大小写
    MYSQL Error 2006HY000:MySQL server has gone away的解决方案
    MySQL之count(*)与count(id)效率比较(转)
    如何让sudo命令不需要输入密码就可执行
  • 原文地址:https://www.cnblogs.com/del/p/1437417.html
Copyright © 2011-2022 走看看