I.T. Discussion Community!
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

November Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyPascal and Delphi Coding BoardDelphi Object PASCAL Topic   Print This     

eConvertError on StrtoDate won't recover

eConvertError on StrtoDate won't recover in Delphi Object PASCAL topic (part of our Pascal and Delphi Coding group).

Quick Search: eConvertError   StrtoDate   won't   recover   eConvertError StrtoDate   eConvertError StrtoDate won't  
Tim Oakley
 (Inactive)
-- USA
We have this simple code that seemed to work fine for years. We are win2k delphi6 (with 2 updates) web app, bde 5.11 hitting oracle 8.0.1.6
---------------------------------------
function IsValidMDYDate(DateText: String): Boolean;
var SaveState: String;
begin
SaveState:=ShortDateFormat;// user default is d/m/yyyy
Result:=True;

try
try
ShortDateFormat:='mm/dd/yyyy';
StrToDate(DateText);
except
on EConvertError do Result:=False;
end;
finally
ShortDateFormat:=SaveState; // restore ShortDateFormat
end;
end;
------------------------------------
The behavior is that it works fine until someone enters a date that fails the conversion. Then no matter what the user enters StrToDate will fail and raise the EConvertError.
The app will have to be restarted to recover.

The ShortDateFormat presented to the users is d/m/yyyy. I have watched(flyover) the changing values of ShortDateFormat come in correctly, change correctly (for the database), then change back correctly. The string value from the user is what I expect too.

Has anyone encountered this?? This is causing failures in a business critical system. I have spent days trying to program around this. Original code included. Thank you!

Tim Oakley
Portland OR
 Posted 16 years ago (Thread Starter)
Comment Quote
About Tim Oakley -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #10757, 4 replies
Thread Started 10/5/2004 1:37:00 PM
View Counter=6711
Last Reply Posted 10/20/2004 1:37:00 PM)
Location=-- USA 
Joined=16 years ago   MB Posts=3  
Rick Carter
Cincinnati OH USA
Be aware that SQL Links has been deprecated for a couple of years now, and the drivers will not be updated. The next Oracle update your company does could blow your application away, unless you move to another method of data access.
Rick Carter
Chair, Delphi/Paradox SIG
Cincinnati PC Users Group
 Posted 16 years ago
Comment Quote
About Rick Carter -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #10770 (Level 1.1)  Reply to 10757
Thread Started 10/11/2004 6:27:00 AM
View Counter=2
Location=Cincinnati OH USA  
Joined=19 years ago   MB Posts=518  
William Pantoja
Woodinville, WA, USA
The StrToDate function actually works well. However, the way you are using it presents some problems.

In your situation, you should use it as below:

function IsValidMDYDate(DateText: String): Boolean;

var
FormatStrings : TFormatStrings;

begin
FormatStrings.DateSeparator := '/';
FormatStrings.ShortDateFormat := 'd/m/yyyy';
FormatStrings.TwoDigitYearCenturyWindow := 50;
try
DateToStr(DateText,FormatStrings);
Result := True;
except
Result := False;
end;
end;
There are two advantages: 1. by explicitly specifying the format strings, we are using a thread-safe version of the function and 2. by not explicitly looking for EConvertError we will only succeed if the conversion succeeds.

I use a simular version of this function in Delphi 6 and 7 and have had no issues.

---
William Pantoja

Consultant/Software Engineer
ForceOne Technologies, Inc.

 Posted 16 years ago
Comment Quote
About William Pantoja -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.

Post ID #10759 (Level 1.2)  Reply to 10757
Reply Posted 10/5/2004 5:31:00 PM
Location=Woodinville, WA, USA  
Joined=19 years ago   MB Posts=163   KB Posts=1  
Tim Oakley
 (Inactive)
-- USA

Originally posted by William Pantoja:

The StrToDate function actually works well. However, the way you are using it presents some problems.

In your situation, you should use it as below:

function IsValidMDYDate(DateText: String): Boolean;

var
FormatStrings : TFormatStrings;

begin
FormatStrings.DateSeparator := '/';
FormatStrings.ShortDateFormat := 'd/m/yyyy';
FormatStrings.TwoDigitYearCenturyWindow := 50;
try
DateToStr(DateText,FormatStrings);
Result := True;
except
Result := False;
end;
end;
There are two advantages: 1. by explicitly specifying the format strings, we are using a thread-safe version of the function and 2. by not explicitly looking for EConvertError we will only succeed if the conversion succeeds.

I use a simular version of this function in Delphi 6 and 7 and have had no issues.


 Posted 16 years ago (Thread Starter)
Comment Quote
About Tim Oakley -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #10787 (Level 1.3)  Reply to 10757
Reply Posted 10/20/2004 1:32:00 PM
Location=-- USA 
Joined=16 years ago   MB Posts=3  
Most Recent Post
Tim Oakley
 (Inactive)
-- USA
You make a very good suggestion. In fact, what you suggested in part was the solution. In some error logging written to a log file, the data seperator was being set to a hyphen. I corrected. Sorry I did not respond sooner. The email reply was stuck in our spamshark trap and I did not see until I checked today. Thanks again, wish I had read a little sooner! Big Grin!
-Tim



Originally posted by William Pantoja:

The StrToDate function actually works well. However, the way you are using it presents some problems.

In your situation, you should use it as below:

function IsValidMDYDate(DateText: String): Boolean;

var
FormatStrings : TFormatStrings;

begin
FormatStrings.DateSeparator := '/';
FormatStrings.ShortDateFormat := 'd/m/yyyy';
FormatStrings.TwoDigitYearCenturyWindow := 50;
try
DateToStr(DateText,FormatStrings);
Result := True;
except
Result := False;
end;
end;
There are two advantages: 1. by explicitly specifying the format strings, we are using a thread-safe version of the function and 2. by not explicitly looking for EConvertError we will only succeed if the conversion succeeds.

I use a simular version of this function in Delphi 6 and 7 and have had no issues.


 Posted 16 years ago (Thread Starter)
Comment Quote
About Tim Oakley -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #10788 (Level 1.4)  Reply to 10757
Reply Posted 10/20/2004 1:37:00 PM
Location=-- USA 
Joined=16 years ago   MB Posts=3  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1287A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #10757 Counter
6711
Since 4/2/2008

Follow PrestwoodBoards on: 


©1995-2020 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech