Тестирование битов 2
unit BitsForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
GroupBox1: TGroupBox;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
Edit1: TEdit;
procedure CheckBoxClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
MyBits: TBits;
procedure UpdateEdit;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
Math;
procedure TForm1.UpdateEdit;
var
I, Total: Integer;
begin
Total := 0;
for I := 0 to 4 do
if MyBits.Bits [I] then
Total := Total + Round (Power (2, I));
Edit1.Text := IntToStr (Total);
end;
procedure TForm1.CheckBoxClick(Sender: TObject);
begin
MyBits.Bits [(Sender as TCheckBox).Tag] :=
not MyBits.Bits [(Sender as TCheckBox).Tag];
UpdateEdit;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyBits := TBits.Create;
MyBits.Size := 5;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
MyBits.Free;
end;
end.
|
Загрузить весь проект
|