Catching database exceptions

I have TTable component with persistent fields pointing to a local table (FoxPro). Further, I have form on which user enters data to my table. I need to catch exceptions which occur when end-user enters invalid value into data-aware component (or such value is assigned to a field programatically in code), for example a string value into TDBEdit that points to TDateField. Such exceptions are raised before actual posting to table, therefore they don't trigger OnPostError event.

Thanks for Help, Ivo.
LVL 2
ivobauerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kretzschmarCommented:
hi ivo,

each tfield has an onvalidate-event, where you canb place your own validation. this event is fired before the vcl tries to place the value into the current record-buffer.

maybe thats a point for you to catch a possible exception before one is raised automatically.

also you can use the onsettext-event of the tfield, by trying to set the value byself into the recordbuffer, and raising an exception byself, if the try failed.

tell me, if you need a sample

meikl
0
ivobauerAuthor Commented:
I'll be very appreciated if you send me some code sample.
0
kretzschmarCommented:
hi ivobauer

samples alternative

procedure TForm1.Table1BirthdayValidate(Sender: TField);
begin
  if Sender.AsDateTime > Now then
    Raise Exception.Create('Error! The Birthday is in the future!');
end;

procedure TForm1.Table1BirthdaySetText(Sender: TField; const Text: String);
begin
  Try
    Sender.AsDateTime := StrToDate(Text);
  except
    raise Exception.Create('There is a problem with the Date-Input!');
  end;
end;

meikl
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ivobauerAuthor Commented:
Posting the points to you. Thanks!
0
kretzschmarCommented:
:-) thanks, hope it helps, good luck again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.