unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, nrclasses, nratcmd, nrgsm, nrbarcode, nrusb, nrlpt, nrcommtapi,
  nrcomm, StdCtrls;

type
  TForm1 = class(TForm)
    nrComm1: TnrComm;
    nrCommTAPI1: TnrCommTAPI;
    nrLPT1: TnrLPT;
    nrUsb1: TnrUsb;
    lbSerial: TListBox;
    lbLpt: TListBox;
    lbModems: TListBox;
    lbUSB: TListBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private     { Private declarations }
  public      { Public declarations }
    procedure UpdateAll;
    procedure ShowAll;
    procedure WMDeviceChange(var Msg:TMessage); message WM_DEVICECHANGE;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

Const
  DBT_DEVICEREMOVECOMPLETE = $8004;
  DBT_DEVICEARRIVAL        = $8000;

{ TForm1 }

procedure TForm1.UpdateAll;
begin
  nrComm1.Update;
  nrLPT1.Update;
  nrCommTAPI1.Update;
  nrUsb1.Update;
end;

procedure TForm1.ShowAll;
begin
  nrComm1.GetDeviceList(lbSerial.Items);
  nrLPT1.GetDeviceList(lbLpt.Items);
  nrCommTAPI1.GetDeviceList(lbModems.Items);
  nrUsb1.GetDeviceList(lbUSB.Items);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ShowAll;
end;

procedure TForm1.WMDeviceChange(var Msg: TMessage);
begin
  if (Msg.WParam = DBT_DEVICEREMOVECOMPLETE)or(Msg.WParam = DBT_DEVICEARRIVAL)
  then begin
    UpdateAll;
    ShowAll;
  end;  
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  UpdateAll;
  ShowAll;  
end;

end.
