Recent

Author Topic: StrToDate exception does not work  (Read 8581 times)

file015

  • New Member
  • *
  • Posts: 12
StrToDate exception does not work
« on: August 31, 2010, 10:43:02 pm »
this will not work properly, does not recognize the error.

procedure TForm1.DatumEditExit(Sender: TObject);
var Datum:TDateTime;
begin

  try Datum:=StrToDate(DatumEdit.Caption)
  except on EconvertError do
  begin
   MessageDlg('wrong date',mtError,[mbOk],0);
   Activecontrol:=DatumEdit;
   exit;

  end;
 end;

Please help. 

lazarus-0.9.28.2-fpc-2.2.4-win32
WinXp_SP3

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: StrToDate exception does not work
« Reply #1 on: September 01, 2010, 12:05:38 am »
Works here. How did you test this?

file015

  • New Member
  • *
  • Posts: 12
Re: StrToDate exception does not work
« Reply #2 on: September 01, 2010, 12:31:36 am »
Works here. How did you test this?

If you turn off ShowMessage then everything is OK, or go to the unknown focus.

mesagedlg and showmessage application we always focus on real problems
« Last Edit: September 01, 2010, 12:34:19 am by file015 »

BlueIcaro

  • Hero Member
  • *****
  • Posts: 793
    • Blog personal
Re: StrToDate exception does not work
« Reply #3 on: September 01, 2010, 12:33:44 am »
this will not work properly, does not recognize the error.

procedure TForm1.DatumEditExit(Sender: TObject);
var Datum:TDateTime;
begin

  try Datum:=StrToDate(DatumEdit.Caption)
  except on EconvertError do
  begin
   MessageDlg('wrong date',mtError,[mbOk],0);
   Activecontrol:=DatumEdit;
   exit;

  end;
 end;

Please help. 

lazarus-0.9.28.2-fpc-2.2.4-win32
WinXp_SP3
In my Lazarus 0.9.29 FPC 2.4.3 SVN 27239 Works nice.
And I have Windows Xp Sp3, as you.

If you run your program from IDE, with the Debuger, you will see that show a expection, then you click continue, you will see your message.

But If you run your program outside of Ide, you will see your message.

/BlueIcaro

file015

  • New Member
  • *
  • Posts: 12
Re: StrToDate exception does not work
« Reply #4 on: September 01, 2010, 09:30:23 am »
lazarus-0.9.28.2-fpc-2.2.4-win32
WinXp_SP3
[/quote]
In my Lazarus 0.9.29 FPC 2.4.3 SVN 27239 Works nice.
And I have Windows Xp Sp3, as you.

If you run your program from IDE, with the Debuger, you will see that show a expection, then you click continue, you will see your message.

But If you run your program outside of Ide, you will see your message.

/BlueIcaro
[/quote]

Shortdateformat is: dd.MM.yy not post
Shortdateformat is: DD.MM.YY to post but only one, other times not.

thank you very much for your help,
 my version of something is not working properly,
Where can I download the version of your Lazarus?

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927

BlueIcaro

  • Hero Member
  • *****
  • Posts: 793
    • Blog personal
Re: StrToDate exception does not work
« Reply #6 on: September 01, 2010, 10:09:32 am »
Hello, you can Download daily Sanpshot, from the menu that you have at your left, in this forum.
Here is a fast link: http://www.hu.freepascal.org/lazarus/

Read, carefully the note, and the wiki: http://wiki.lazarus.freepascal.org/Lazarus_Snapshots_Downloads

I don't download all the days a snapshot, but I do it, sometimes, when my lazarus is geetting old, or I found a problem, and after search throught the forum, or the bug tracker, I saw that I need upgrade.

Also I read the forum, when I see that many people has problems, and many answers says, that they must upgrade, I do it.

Also I keep the lazarus's instalaler that I have working, because sometimes I got a new snapshoot and I have problems, so I have the old file to go back.

/BlueIcaro

/BlueIcaro

file015

  • New Member
  • *
  • Posts: 12
Re: StrToDate exception does not work
« Reply #7 on: September 02, 2010, 10:26:39 pm »
The error has been found, if  Form1  keypreview = true and shortformatdate<> DD.MM.YY (dd.MM.yy) , then this is not working properly, go to the wrong focus.
   Thank you very much for your help.
« Last Edit: September 02, 2010, 10:28:52 pm by file015 »

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: StrToDate exception does not work
« Reply #8 on: April 17, 2020, 02:32:32 pm »
We should set:
1°) first of all, the DateSeparator to '.' (or '/', or '-').
2°) and then, the FormatSettings.ShortDateFormat to 'yyyy.mm.dd' (or 'yyyy/mm/dd', or 'yyyy-mm-dd', in accordance with the chosen separator date).

For example:
Code: Pascal  [Select][+][-]
  1. DateSeparator := '-';
  2. FormatSettings.ShortDateFormat := 'yyyy-mm-dd';
Instead, set FormatSettings.ShortDateFormat is only used to determine the order of ...the DateSeparator.

If we need more powerful string to date conversion, check this:
https://www.freepascal.org/docs-html/rtl/dateutils/scandatetime.html.

Thanks to Michael Van Canneyt.
« Last Edit: April 17, 2020, 02:55:32 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

 

TinyPortal © 2005-2018