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
    

  • 相关阅读:
    iOS 简单获取当前地理坐标
    iOS 企业账号申请证书和打包ipa
    iOS 代码片段的添加!
    iOS 扩展类方法之category!
    iOS 数组和字典排序
    iOS 字符串NSString 的一些常用方法
    iOS 一些常见问题
    iOS 数据库sqlite完整增删改查操作
    iOS pch文件的创建
    iOS 通过网络请求获取图片的下载歌曲
  • 原文地址:https://www.cnblogs.com/del/p/1437417.html
Copyright © 2011-2022 走看看