unit AddPropSetDlgUnit;

{
Autor: Набережных С.Н.
Creation:       21/01/2006
Last modified:  -
}

interface

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

type
  TfrmAddPropSet = class(TForm)
    Label1: TLabel;
    edSetID: TEdit;
    Label2: TLabel;
    edSetName: TEdit;
    bbOk: TBitBtn;
    bbCancel: TBitBtn;
    btnGenID: TButton;
    procedure btnGenIDClick(Sender: TObject);
    procedure edSetIDChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    class function Execute(out ID: TGUID; out NewSetName: WideString): boolean;
  end;

implementation

uses
  ActiveX, ComObj;

{$R *.dfm}

{ TfrmAddPropSet }

class function TfrmAddPropSet.Execute(out ID: TGUID;
  out NewSetName: WideString): boolean;
begin
  with Self.Create(Application) do
  try
    repeat
      Result:= ShowModal = mrOk;
      if not Result then break;
      try
        ID:= StringToGUID(edSetID.Text);
      except
        Application.MessageBox(PChar('Invalid ID string!'), 'Error', MB_ICONERROR);
        ActiveControl:= edSetID;
        Continue;
      end;
      NewSetName:= edSetName.Text;
      Break;
    until false;
  finally
    Free;
  end;
end;

procedure TfrmAddPropSet.btnGenIDClick(Sender: TObject);
var
  ID: TGUID;
begin
  OleCheck(CoCreateGuid(ID));
  edSetID.Text:= GUIDToString(ID);
end;

procedure TfrmAddPropSet.edSetIDChange(Sender: TObject);
begin
  bbOk.Enabled:= edSetID.Text <> '';
end;

end.
