boardtc
asked on
exception raised showing too late with 1899 date
I am raising an exception inside a with statement that displays a message to the screen, however it is not displaying when it should. I trace through the code and the raise is called, however, another number of lines of code are run before the message displays. Is this normal?
Also, evaluating the exception message, it shows a FormatDateTime returns a 1999 date which is correct but when the message eventually shows it says 1899?
I am running D4.03 C/S, the exception is raised if the result of a SQL query on a SQL server table is null.
Thanks a lot, Tom.
Also, evaluating the exception message, it shows a FormatDateTime returns a 1999 date which is correct but when the message eventually shows it says 1899?
I am running D4.03 C/S, the exception is raised if the result of a SQL query on a SQL server table is null.
Thanks a lot, Tom.
Can you post some source code?
ASKER
Cheers, here is some:
with QueryIn do
begin
{retrieve info re: date}
Close;
SQL.Clear;
SQL.Add('SELECT * FROM CALENDAR WHERE Date=:Date');
Prepare;
ParamByName('Date').AsDate := dDateIn;
Open;
if NOT EOF then
begin
if GetIntegerParam(FieldByNam e('DayOfWe ek')) = WEDNESDAY then
bIsWednesday := TRUE;
bIsLBDOM := GetBooleanParam(FieldByNam e('LBDOM') );
end
else
raise ECalcException.Create('Ind exRecord Retrieve: ' + FormatDateTime('dd-mmm-yyy y', dDateIn) + ' does not belong to the CALENDAR table.');
Close;
end;
with QueryIn do
begin
{retrieve info re: date}
Close;
SQL.Clear;
SQL.Add('SELECT * FROM CALENDAR WHERE Date=:Date');
Prepare;
ParamByName('Date').AsDate
Open;
if NOT EOF then
begin
if GetIntegerParam(FieldByNam
bIsWednesday := TRUE;
bIsLBDOM := GetBooleanParam(FieldByNam
end
else
raise ECalcException.Create('Ind
Close;
end;
What you must do right after setting the SQL text is to tell Delphi that the datatype of the parameter "Date" is DateTime. This way it will be able to correctly mount the SQL query.
You can do that by using TParam.DataType and TParam.ParamType.
Another thing: make sure that dDateIn is a number > 0.
The fact that the Raise message box is returning 1899 is because dDateIn is probably 0, which corresponds to 30/12/1899, or 1 ( = 31/12/1899).
The exception will be raised if there are not records returned by the query, so EOF will be true.
Another thing: make sure that no other functions are altering the value of dDateIn (like in the events of the TQuery objects).
Alex
Raising an exception does not cause a message to be displayed to the screen.
The action that is taken when an exception occurs depends on the exception handler that traps the exception. The default exception handler for any unhandled exceptions is to display the text of the exception in a dialog box.
By the time this exception handler has been called, your program will have 'unwound' to the top of the call stack, and the next instruction to be executed will be at the application.run level, which will probably be in response to a windows message.
The action that is taken when an exception occurs depends on the exception handler that traps the exception. The default exception handler for any unhandled exceptions is to display the text of the exception in a dialog box.
By the time this exception handler has been called, your program will have 'unwound' to the top of the call stack, and the next instruction to be executed will be at the application.run level, which will probably be in response to a windows message.
ASKER
Thank you both very much for the comments. Alex, good info, I actually am setting the datatype to ftDate, it was a fucntion call that I pulled out of the above code. I will follow up to see if dDateIn is zero. Pearce, thanks for the info on exception handling, I need to lok into it more, I am especially curious when it's a good time to use exceptions over messagedlg's. Thanks again. Tom.
hi all,
just a remark,
use this
ParamByName('Date').AsDate Time := dDateIn;
instead of
ParamByName('Date').AsDate := dDateIn;
meikl
just a remark,
use this
ParamByName('Date').AsDate
instead of
ParamByName('Date').AsDate
meikl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks everyone for the advice. Tom.
tom,
did you really got new information
about the accepted answer?
or have you just waited,
until somewhere post an answer
meikl
did you really got new information
about the accepted answer?
or have you just waited,
until somewhere post an answer
meikl
Why did you accept the answer?
ASKER
Meikl, I am sorry, this is always the case with this system, I got most information from AdPearce, but there doesn't seem to be a way to split the points, so I took the easy way out. Sorry about that, it was lazy. Tom.
>but there doesn't seem to be a way to
>split the points
YES, THERE IS.
You could have asked the folks in Customer Service to split the points.
Since you took the easy way out, so will I, by not answering any of your future questions.
Alex
>split the points
YES, THERE IS.
You could have asked the folks in Customer Service to split the points.
Since you took the easy way out, so will I, by not answering any of your future questions.
Alex
Petty, petty. My goodness, what is this? Are the points that important?
It's not a matter of points. It's a matter of attitude and respect.
Pretend every expert would do as tom and take the easy way, by giving lousy answers and making useless comments. That's very easy to do, but the experts strive to give answers to the best of their abilities. That's our part of the bargain. The user's part of the bargain is not to take the easy way, but to give credit where it's due.
Alex
Pretend every expert would do as tom and take the easy way, by giving lousy answers and making useless comments. That's very easy to do, but the experts strive to give answers to the best of their abilities. That's our part of the bargain. The user's part of the bargain is not to take the easy way, but to give credit where it's due.
Alex
ASKER
Alex, I have to apologize to you. I know I dod wrong and I ask to be given a second chance. I have emailed support and asked them to add 50 points to your account. Thanks again. Tom.