Datetime issues lazarus / 16-Databases ---------------------------------------------------------------------- mangakissa · 2014-03-18 21:31 Filling a TDBEdit as DateTimefield (example 40-40-2000) occurs an error. The application give a dialog where you can choose OK to go further and Cancel to close the application. Why is it a risk to go further? Why closes my application completely when I choose CANCEL? Who is giving this Dialog? How can I run my application normal without this dialog? ---------------------------------------------------------------------- taazz · 2014-03-18 21:52 Quote from: mangakissa on March 18, 2014, 10:31:47 pmFilling a TDBEdit as DateTimefield (example 40-40-2000) occurs an error. The application give a dialog where you can choose OK to go further and Cancel to close the application. Why is it a risk to go further? it is not a risk, its just the defalt exception dialog a lot of problems with this but hey you can change it as far as I know. Quote from: mangakissa on March 18, 2014, 10:31:47 pmWhy closes my application completely when I choose CANCEL? well the message says it all press cancel to kill the application aka exit when pressing cancel so as expected. Quote from: mangakissa on March 18, 2014, 10:31:47 pmWho is giving this Dialog? Default dialog comes with LCL. Quote from: mangakissa on March 18, 2014, 10:31:47 pmHow can I run my application normal without this dialog? add a appliction.onexception handler and show your own message or simple ignore it. Not a good practise in my book but the only work around I know. ---------------------------------------------------------------------- marcov · 2014-03-19 13:17 I think it is simply bad programming.  A droppable component should never generate exceptions like econverterror. Please file a bug. (and test the/a similar case with delphi if you can) ---------------------------------------------------------------------- mangakissa · 2014-03-19 21:24 Delphi also creates a  econverterror., but doesn't crash. Create a small Delphi application (TClientdataset) and a small Lazarus application (TBufdataset). Delphi does continue. ---------------------------------------------------------------------- mangakissa · 2014-03-20 08:07 Also reported in bugtracker ---------------------------------------------------------------------- wp · 2014-03-21 13:34 In my own applications I usually try to avoid exceptions. Therefore, if there is an input control I check the input data before passing them to other structures. In your demo application, I originally thought it would be sufficient to catch the incorrect input in the BeforePost event of the dataset. But since you are using a DBEdit the error happens way before posting when the edit converts the string to a field value. Luckily there is another event to catch the error: Use the OnGetText event of the field linked to the DBEdit. This is called when the field of the Dataset "gets" the string from the connected data-sensitive control and converts it to the data type needed. In case of an error, call "Abort" to raise a silent exception. Code: [Select]procedure TForm1.BufDataset1birthday1SetText(Sender: TField; const aText: string   ); var   d: TDate; begin   if (AText = '') then begin     MessageDlg('Input required for birthday', mtError, [mbOK], 0);     Abort;   end;   if not TryStrToDate(AText, d) then begin     MessageDlg(Format('"%s" is not a valid date.', [AText]), mtError, [mbOk], 0);     Abort;   end; end; ---------------------------------------------------------------------- mangakissa · 2014-03-21 15:32 Thanks. I shall look at your workaround. But it's still a real bug.