unit Unit3;

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
  TForm3 = 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;
    ComboBox1: TComboBox;
    Label6: TLabel;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

uses
  Unit1, pub;

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
var
  s: string;
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);
      if Form1.ListView1.Selected<>nil then
      begin
        if Form1.ListView1.Selected.Index<DataLoad.Count then
        begin
          DataLoad[Form1.ListView1.Selected.Index]:=s;
          DataLoad.SaveToFile(MainDir + 'rdp.dat');
          Form1.ListView1.Selected.Caption:=Edit1.Text;
          Form1.ListView1.Selected.SubItems[0]:=Edit2.Text + ':' + Edit3.Text;
        end;
      end;
      Close;
    end;
  end;
end;

procedure TForm3.Button2Click(Sender: TObject);
begin
  Close;
end;

end.

