{*=====================================================================
  Project:   BitWiseTest.bdsproj

  File:      WinForm.pas

  Summary:   A very simple demo for bitwise shl and shr operations
             implemented in ByteBitWise Class.

---------------------------------------------------------------------
  This file is submitted by:

	 endresy@axelero.hu
	 Endre I. Simay,
	 Hungary

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
=====================================================================*}
unit WinForm;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms, System.Data,
  SysUtils,
  bitwiseclass
  ;

type
  TWinForm = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    /// <summary>
    /// Required designer variable.
    /// </summary>
    Components: System.ComponentModel.Container;
    Button1: System.Windows.Forms.Button;
    TextBox1: System.Windows.Forms.TextBox;
    TextBox2: System.Windows.Forms.TextBox;
    TextBox3: System.Windows.Forms.TextBox;
    TextBox4: System.Windows.Forms.TextBox;
    Label1: System.Windows.Forms.Label;
    Label2: System.Windows.Forms.Label;
    Label3: System.Windows.Forms.Label;
    Label4: System.Windows.Forms.Label;
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    procedure InitializeComponent;
    procedure Button1_Click(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    procedure Dispose(Disposing: Boolean); override;
  public
    constructor Create;
  end;

implementation

uses
  System.Globalization;

{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWinForm.InitializeComponent;
begin
  Self.Button1 := System.Windows.Forms.Button.Create;
  Self.TextBox1 := System.Windows.Forms.TextBox.Create;
  Self.TextBox2 := System.Windows.Forms.TextBox.Create;
  Self.TextBox3 := System.Windows.Forms.TextBox.Create;
  Self.TextBox4 := System.Windows.Forms.TextBox.Create;
  Self.Label1 := System.Windows.Forms.Label.Create;
  Self.Label2 := System.Windows.Forms.Label.Create;
  Self.Label3 := System.Windows.Forms.Label.Create;
  Self.Label4 := System.Windows.Forms.Label.Create;
  Self.SuspendLayout;
  // 
  // Button1
  // 
  Self.Button1.Location := System.Drawing.Point.Create(104, 80);
  Self.Button1.Name := 'Button1';
  Self.Button1.Size := System.Drawing.Size.Create(72, 24);
  Self.Button1.TabIndex := 0;
  Self.Button1.Text := 'Calculate';
  Include(Self.Button1.Click, Self.Button1_Click);
  // 
  // TextBox1
  // 
  Self.TextBox1.Location := System.Drawing.Point.Create(24, 48);
  Self.TextBox1.Name := 'TextBox1';
  Self.TextBox1.Size := System.Drawing.Size.Create(56, 20);
  Self.TextBox1.TabIndex := 1;
  Self.TextBox1.Text := '0';
  // 
  // TextBox2
  // 
  Self.TextBox2.Location := System.Drawing.Point.Create(208, 48);
  Self.TextBox2.Name := 'TextBox2';
  Self.TextBox2.Size := System.Drawing.Size.Create(56, 20);
  Self.TextBox2.TabIndex := 2;
  Self.TextBox2.Text := '0';
  // 
  // TextBox3
  // 
  Self.TextBox3.Location := System.Drawing.Point.Create(24, 120);
  Self.TextBox3.Name := 'TextBox3';
  Self.TextBox3.Size := System.Drawing.Size.Create(56, 20);
  Self.TextBox3.TabIndex := 3;
  Self.TextBox3.Text := '0';
  // 
  // TextBox4
  // 
  Self.TextBox4.Location := System.Drawing.Point.Create(208, 120);
  Self.TextBox4.Name := 'TextBox4';
  Self.TextBox4.Size := System.Drawing.Size.Create(56, 20);
  Self.TextBox4.TabIndex := 4;
  Self.TextBox4.Text := '0';
  // 
  // Label1
  // 
  Self.Label1.Location := System.Drawing.Point.Create(24, 24);
  Self.Label1.Name := 'Label1';
  Self.Label1.Size := System.Drawing.Size.Create(56, 16);
  Self.Label1.TabIndex := 5;
  Self.Label1.Text := 'Left';
  // 
  // Label2
  // 
  Self.Label2.Location := System.Drawing.Point.Create(208, 24);
  Self.Label2.Name := 'Label2';
  Self.Label2.Size := System.Drawing.Size.Create(56, 16);
  Self.Label2.TabIndex := 6;
  Self.Label2.Text := 'Right';
  // 
  // Label3
  // 
  Self.Label3.Location := System.Drawing.Point.Create(24, 96);
  Self.Label3.Name := 'Label3';
  Self.Label3.Size := System.Drawing.Size.Create(56, 16);
  Self.Label3.TabIndex := 7;
  Self.Label3.Text := 'Shl';
  // 
  // Label4
  // 
  Self.Label4.Location := System.Drawing.Point.Create(208, 96);
  Self.Label4.Name := 'Label4';
  Self.Label4.Size := System.Drawing.Size.Create(56, 16);
  Self.Label4.TabIndex := 8;
  Self.Label4.Text := 'Shr';
  // 
  // TWinForm
  // 
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13);
  Self.ClientSize := System.Drawing.Size.Create(292, 266);
  Self.Controls.Add(Self.Label4);
  Self.Controls.Add(Self.Label3);
  Self.Controls.Add(Self.Label2);
  Self.Controls.Add(Self.Label1);
  Self.Controls.Add(Self.TextBox4);
  Self.Controls.Add(Self.TextBox3);
  Self.Controls.Add(Self.TextBox2);
  Self.Controls.Add(Self.TextBox1);
  Self.Controls.Add(Self.Button1);
  Self.Name := 'TWinForm';
  Self.Text := 'WinForm';
  Self.ResumeLayout(False);
end;
{$ENDREGION}

procedure TWinForm.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor TWinForm.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;

procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var
 bitWise : TByteBitWise;
begin
 bitWise := TByteBitWise.Create;
 try
  textBox3.Text := bitWise.byteshl(StrToInt(textBox1.Text),StrToInt(textBox2.Text)).ToString('x');
  textBox4.Text := bitWise.byteshr(StrToInt(textBox1.Text),StrToInt(textBox2.Text)).ToString('x');
 except
	MessageBox.Show('Problem with conversion.' + 'Sorry', 'Conversion Error',
								MessageBoxButtons.OK);
 end;
end;

end.
