unit MainUnit;

interface

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

type
  TfrmParams = class(TForm)
    ldePort: TLabeledEdit;
    ldeIP: TLabeledEdit;
    btnOK: TButton;
    btnClose: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
    procedure btnCloseClick(Sender: TObject);
  private
    FcfgParams: TScCfgPort;
  public
    { Public declarations }
  end;

var
  frmParams: TfrmParams;

implementation

{$R *.dfm}

procedure TfrmParams.FormCreate(Sender: TObject);
begin
  FcfgParams := TScCfgPort.Create;
  FcfgParams.ReadPort;
  ldePort.Text := IntToStr(FcfgParams.Port);
  ldeIP.Text := FcfgParams.IP;
end;

procedure TfrmParams.FormDestroy(Sender: TObject);
begin
  FcfgParams.Free;
end;

procedure TfrmParams.btnOKClick(Sender: TObject);
begin
  try
  FcfgParams.Port := StrToInt(ldePort.Text);
  FcfgParams.IP := ldeIP.Text;
  except
    MessageBox(0, PChar('输入了非法字符，请重新输入！'), PChar('错误'), MB_OK or MB_ICONERROR);
    Exit;
  end;
  FcfgParams.WritePort;

  Close;
end;

procedure TfrmParams.btnCloseClick(Sender: TObject);
begin
  Close;
end;

end.
