Board index » delphi » Validating a Date Field

Validating a Date Field

Hi,

I have a TDBEdit component that associated to DataAbertura qryPSTLivro's
field.
I'd like to validate the text when i fill the DataAbertura field with a
invalid
date. I got with follow procedure:

procedure TdmPosto.qryPSTLivroDataAberturaSetText(Sender: TField;
  const Text: String);
begin
  inherited;
  try
    qryPSTLivroDataAbertura.AsDateTime := StrToDate(Text);
  except
    ShowMessage('Data invlida');
  end;
end;

But when i don't fill the TDBEdit component and i try to exit component,
i don't get to pass by over code.

Please, anyone knows whats happening ?

Thanks,

------------------------------

--
Gustavo Halmenschlager
Setor de Informtica
Contas Mdicas Ltda.

 

Re:Validating a Date Field


Hi,

I have a TDBEdit component that associated to DataAbertura qryPSTLivro's
field.
I'd like to validate the text when i fill the DataAbertura field with a
invalid
date. I got with follow procedure:

procedure TdmPosto.qryPSTLivroDataAberturaSetText(Sender: TField;
  const Text: String);
begin
  inherited;
  try
    qryPSTLivroDataAbertura.AsDateTime := StrToDate(Text);
  except
    ShowMessage('Data invlida');
  end;
end;

But when i don't fill the TDBEdit component and i try to exit component,
i don't get to pass by over code.

Please, anyone knows whats happening ?

Thanks,

------------------------------

--
Gustavo Halmenschlager
Setor de Informtica
Contas Mdicas Ltda.

Re:Validating a Date Field


Quote
>But when i don't fill the TDBEdit component and i try to exit component,
>i don't get to pass by over code.

Are you using an Edit mask on the Tfield?
if so use code like this in the  TDBEdit.OnChange event

procedure TMyForm.dbeditMaskChange(Sender: TObject);
begin
  with Sender as TDBEdit do
    if Modified then
    begin
      ModifiedForm := True;
      if (Text = '') or
         (Text = FormatMaskText(MyTable.FieldByName(DataField).EditMask, '))
then
      begin
        MyTable.FieldByName(DataField).Clear;
        Modified := False;
      end;
    end;
end;

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Other Threads