Page 1 of 1

TSQLTimeStamp Validation Issue

Posted: Wed 01 Aug 2012 15:39
by mmalinow
Hello,

Hoping you can give some feedback. Using dbexpoda40.dll with Delphi 2010.
On exiting a DBEdit whose field type is a TSQLTimeStampField when an invalid date is entered, I receive the exception "Could not parse SQL TimeStamp String". I am attempting to intercept this exception to give the user a more specific message. Do you have any suggestions as to an approach?

Thank you,
Mike Malinowski
PRG

Re: TSQLTimeStamp Validation Issue

Posted: Thu 02 Aug 2012 09:48
by AlexP
hello,

To intercept this error, you can use the SetText event of this field, or validate the inserted data by yourself using the TryStrToSqlTimeStamp method:

Code: Select all

procedure TForm1.ClientDataSet1F_TIMESTAMPSetText(Sender: TField;
  const Text: string);
var
  Value: TSQLTimeStamp;
begin
  if TryStrToSqlTimeStamp(Text, Value) then
    TSQLTimeStampField(Sender).SetData(@Value, False)
  else
    ShowMessage('Error');}
end;
or intercept this error:

Code: Select all

procedure TForm1.ClientDataSet1F_TIMESTAMPSetText(Sender: TField;
  const Text: string);
begin
  try
    TSQLTimeStampField(Sender).AsString :=  Text;
  except
    on e: EConvertError do
      ShowMessage(e.Message);
  end;
end;

Re: TSQLTimeStamp Validation Issue

Posted: Thu 02 Aug 2012 12:06
by mmalinow
Hello,

Have not implemented yet.
Just wanted to thank you for your reply.

Mike Malinowski