unit DataDlg;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,globalvar;

type
  TDataFrm = class(TForm)
    LBusTypeSel: TLabel;
    CBusTypeSel: TComboBox;
    LAddress: TLabel;
    Address: TEdit;
    LIrq: TLabel;
    Irq: TEdit;
    LMessage: TLabel;
    btnEnter: TButton;
    btnCancel: TButton;
    LClose1: TLabel;
    LClose2: TLabel;
    procedure CBusTypeSelChange(Sender: TObject);
    procedure AddressKeyPress(Sender: TObject; var Key: Char);
    procedure IrqKeyPress(Sender: TObject; var Key: Char);
    procedure AddressExit(Sender: TObject);
    procedure IrqExit(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  DataFrm: TDataFrm;

implementation

{$R *.dfm}

procedure TDataFrm.CBusTypeSelChange(Sender: TObject);
begin
    if CBusTypeSel.ItemIndex=0 then
    begin
      DataFrm.Address.Enabled:=false;
      DataFrm.Address.Text:='65535';
    end
    else
    begin
      DataFrm.Address.Enabled:=true;
      DataFrm.Address.Text:='768';
    end;
end;

procedure TDataFrm.AddressKeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in DigitsSet) then
   begin
       key:=#0;
       exit;
   end;
end;

procedure TDataFrm.IrqKeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in DigitsSet) then
   begin
       key:=#0;
       exit;
   end;
end;

procedure TDataFrm.AddressExit(Sender: TObject);
begin
  if (Address.Text='') or (StrToFloat(Address.Text)<0)  then
   begin
       if lang=1 then
         ShowMessage('输入值错误，重新输入。')
       else
         ShowMessage('Error input.');
       Address.SetFocus();
       exit;
   end;
end;

procedure TDataFrm.IrqExit(Sender: TObject);
begin
  if (Irq.Text='') or (StrToFloat(Irq.Text)<0)  then
   begin
       if lang=1 then
         ShowMessage('输入值错误，重新输入。')
       else
         ShowMessage('Error input.');
       Irq.SetFocus();
       exit;
   end;
end;

procedure TDataFrm.FormShow(Sender: TObject);
begin
   if lang=1 then
   begin
      btnEnter.Caption:='确定(&o)';
      btnCancel.Caption:='取消(&c)';
   end
   else begin
      btnEnter.Caption:='Confirm(&o)';
      btnCancel.Caption:='Cancel(&c)';
   end;
end;

end.
