现在的位置: 首页[Delphi技巧]>正文
用一个 Byte 数表示 8 个复选框的选择状态
2009年04月17日 [Delphi技巧] 评论数 2

操作界面效果:


代码如下:

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);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
var
num: Integer;


procedure TForm1.FormCreate(Sender: TObject);
var
i : Integer ;
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.


代码文件下载:200904170029140353.rar

目前有 2 条留言 其中:访客:2 条, 博主:0 条

  1. godyad : 2009年05月16日21:25:12  1楼 @回复 回复

    呵呵~在网络上看到的,就写下

  2. delphi : 2009年05月12日23:09:28  2楼 @回复 回复

    偶系delphi,
    星,这个是祢写的?
    好好玩哦..

给我留言

留言无头像?


×
腾讯微博