unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.StdCtrls, Vcl.ComCtrls;

type
  TForm2 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Label3: TLabel;
    Edit3: TEdit;
    Label4: TLabel;
    Edit4: TEdit;
    Label5: TLabel;
    Edit5: TEdit;
    Button1: TButton;
    Button2: TButton;
    Label6: TLabel;
    ComboBox1: TComboBox;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses
  Unit1, pub;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
var
  s: string;
  it: TListItem;
begin
  if Edit1.Text = '' then
  begin
    ShowMessage('主机名称不能为空');
    Edit1.SetFocus;
  end
  else if Edit2.Text = '' then
  begin
    ShowMessage('主机地址不能为空');
    Edit2.SetFocus;
  end
  else if Edit3.Text = '' then
  begin
    ShowMessage('主机端口不能为空');
    Edit3.SetFocus;
  end
  else if Edit4.Text = '' then
  begin
    ShowMessage('管理帐号不能为空');
    Edit4.SetFocus;
  end
  else
  begin
    s := Edit1.Text + Edit2.Text + Edit3.Text + Edit4.Text + Edit5.Text;
    if Pos('|', s) > 0 then
    begin
      ShowMessage('输入的内容不支持 数据分隔符 “|”');
    end
    else
    begin
      s := Edit1.Text + '|' + Edit2.Text + '|' + Edit3.Text + '|' + Edit4.Text + '|' + Edit5.Text+'|'+inttostr(ComboBox1.ItemIndex);
      DataLoad.Add(s);
      DataLoad.SaveToFile(MainDir + 'rdp.dat');
      it := Form1.ListView1.Items.Add;
      it.Caption := Edit1.Text;
      it.SubItems.Add(Edit2.Text + ':' + Edit3.Text);
      Close;
    end;
  end;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
  close;
end;

end.

