Page 1 of 1

date parambyname

Posted: Fri 13 Apr 2012 06:53
by andrea.m86
Hi
I encountered this problem.
this kind of expression doesn't always work properly:

query1: TMyQuery;
datecomponent: (3rd party component);

query1.parambyname('start_date').value := datecomponent.date;

I solved using:

query1.parambyname('start_date').asdate := datecomponent.date;

but I have a lot of code already written to fix and in some other case i don't know in advance if the param that i will pass to my query is a date or something else, so i must use ".value"

Posted: Fri 13 Apr 2012 11:22
by AndreyZ
Hello,

If you want to use the Value property, your third-party components (the datecomponent.date property) have to return dates as TDateTime. If they don't do it, please write about this problem to developers of your third-party components. Also, you can solve this problem in the way you have already found, by using the AsDate property instead of Value. Or you can explicitly cast datecomponent.date to TDateTime, for example:

Code: Select all

query1.parambyname('start_date').value := TDateTime(datecomponent.date);

Posted: Fri 13 Apr 2012 15:23
by andrea.m86
Ok. Thanks!
actually my components pass a TDate instead of a TDateTime.
I solved by modifying the unit of the component and it seems ok!

Posted: Tue 17 Apr 2012 06:50
by AndreyZ
It's good to see that the problem was solved. If any other questions come up, please contact us.