unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, nrcommbox, nrclasses, nrlpt, nrlogfile, XPMan;

type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    nrLPT1: TnrLPT;
    nrDeviceBox1: TnrDeviceBox;
    boxPins: TGroupBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    CheckBox7: TCheckBox;
    CheckBox8: TCheckBox;
    CheckBox9: TCheckBox;
    CheckBox10: TCheckBox;
    CheckBox11: TCheckBox;
    CheckBox12: TCheckBox;
    CheckBox13: TCheckBox;
    CheckBox14: TCheckBox;
    CheckBox15: TCheckBox;
    CheckBox16: TCheckBox;
    CheckBox17: TCheckBox;
    CheckBox18: TCheckBox;
    CheckBox19: TCheckBox;
    CheckBox20: TCheckBox;
    CheckBox21: TCheckBox;
    CheckBox22: TCheckBox;
    CheckBox23: TCheckBox;
    CheckBox24: TCheckBox;
    CheckBox25: TCheckBox;
    CheckBox26: TCheckBox;
    Button1: TButton;
    ebase: TEdit;
    nrLogFile1: TnrLogFile;
    XPManifest1: TXPManifest;
    Memo1: TMemo;
    Button2: TButton;
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure CheckBox19Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public   { Public declarations }
    procedure UpdateControls;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  try
    if CheckBox1.Checked
      then nrLpt1.LptIOBase := StrToInt('$' + eBase.Text);
    nrLpt1.Active := CheckBox1.Checked;
    if nrLpt1.Active then Button1Click(Sender);
    UpdateControls;    
  except
    CheckBox1.Checked:=nrLpt1.Active;
    raise;
  end;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
  nrLpt1.Pins[TCheckBox(Sender).Tag]:=TCheckBox(Sender).Checked;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
  for i:=0 to boxPins.ControlCount-1 do
    if boxPins.Controls[i].Tag<>0
      then TCheckBox(boxPins.Controls[i]).Checked:=nrLpt1.Pins[boxPins.Controls[i].Tag];
end;

procedure TForm1.CheckBox19Click(Sender: TObject);
begin
  TCheckBox(Sender).State:=cbGrayed;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  eBase.Text := IntToHex(nrLPT1.LptIOBase, 8);
  UpdateControls;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  nrLpt1.SendString(Memo1.Text);
end;

procedure TForm1.UpdateControls;
begin
  boxPins.Enabled := nrLpt1.Active;
  Memo1.Enabled := nrLpt1.Active;
  Button2.Enabled := nrLpt1.Active;
  ebase.Enabled := not nrLpt1.Active;
  nrDeviceBox1.Enabled := not nrLpt1.Active;
end;

end.
