unit messageEntries;

interface

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

type
  ITextParent = interface ['{9F885233-D24D-41B5-B8CA-271866416AB1}']
   function IsExistText(text:string):boolean;
  end;

  TMessageEntryDlg = class(TForm)
    Label1: TLabel;
    CancelBtn: TButton;
    Edit1: TEdit;
    OKBtn: TButton;
    procedure CancelBtnClick(Sender: TObject);
    procedure OKBtnClick(Sender: TObject);
  private
    { Private 宣言 }
    lastText:string;
  public
    { Public 宣言 }
    TextParent:ITextParent;
    function getNewName():string;
    procedure setEditText(text:string);
  end;

var
  messageEntryDlg: TMessageEntryDlg;

implementation

{$R *.dfm}

function TMessageEntryDlg.getNewName():string;
begin
 result:=Edit1.Text;
end;

procedure TMessageEntryDlg.setEditText(text:string);
begin
 Edit1.Text:=text;
 lastText:=text;
end;

procedure TMessageEntryDlg.CancelBtnClick(Sender: TObject);
begin
 ModalResult := mrCancel;
end;

procedure TMessageEntryDlg.OKBtnClick(Sender: TObject);

begin
 if (AnsiLowerCase((trim(Edit1.Text)))='init')then
  Label1.Caption:='利用できない名前です'
 else if(TextParent<>nil)then
  if(lastText=Edit1.Text)or not (TextParent.IsExistText(Edit1.Text))then
   ModalResult := mrOK
 else
  Label1.Caption:='名前が重複してます';
end;

end.
 
