unit AddPropDlgUnit;

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

interface

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

type
  TfrmAddProperty = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    edPropID: TEdit;
    edPropName: TEdit;
    bbOK: TBitBtn;
    bbCancel: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure edPropNameChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    class function Execute(out ID: Cardinal; out PropName: WideString): boolean;
  end;

implementation

{$R *.dfm}

class function TfrmAddProperty.Execute(out ID: Cardinal;
  out PropName: WideString): boolean;
begin
  with Self.Create(Application) do
  try
    Result:= ShowModal = mrOk;
    if Result then
    begin
      if '' = edPropID.Text then ID:= 0 else
      begin
        ID:= Cardinal(StrToInt(edPropID.Text));
        if ID < 2 then ID:= 0;
      end;
      PropName:= Trim(edPropName.Text);
    end;
  finally
    Free;
  end;
end;

procedure TfrmAddProperty.FormCreate(Sender: TObject);
begin
  SetWindowLong(edPropID.Handle, GWL_STYLE,
    ES_NUMBER or GetWindowLong(edPropID.Handle, GWL_STYLE));
end;

procedure TfrmAddProperty.edPropNameChange(Sender: TObject);
begin
  bbOK.Enabled:= ('' <> Trim(edPropName.Text)) or
    (('' <> edPropID.Text) and (1 < StrToInt(edPropID.Text)));
end;

end.
