Recent

Author Topic: Issues with TDateTimePicker  (Read 440 times)

BSaidus

  • Sr. Member
  • ****
  • Posts: 304
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Issues with TDateTimePicker
« on: November 15, 2019, 09:39:39 pm »
Hello.
I want to use TDateTimePicker in a simple program ( one form ) and retreive a Date from the DateTimePicker construct a Query and post it to database.
But when I put the Value of Date to Null it doesnt work.
I think that the DateTimePicker.Date is never NULL or 0.
How to do that.
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

dsiders

  • Full Member
  • ***
  • Posts: 238
Re: Issues with TDateTimePicker
« Reply #1 on: November 15, 2019, 10:46:58 pm »
Hello.
I want to use TDateTimePicker in a simple program ( one form ) and retreive a Date from the DateTimePicker construct a Query and post it to database.
But when I put the Value of Date to Null it doesnt work.
I think that the DateTimePicker.Date is never NULL or 0.
How to do that.

Use the NullDate constant for an empty date/time value in the control. You have to decide what gets put into the database. TDBDateTimePicker handles the conversion in its UpdateData method.
Lazarus 2.0.4 / FPC 3.0.4 / Windows 8.1 64-bit

BSaidus

  • Sr. Member
  • ****
  • Posts: 304
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: Issues with TDateTimePicker
« Reply #2 on: November 17, 2019, 02:01:08 pm »
Thank you @dsider for the advice.
It works .
lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

BSaidus

  • Sr. Member
  • ****
  • Posts: 304
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: Issues with TDateTimePicker
« Reply #3 on: November 19, 2019, 11:29:06 am »
The problem persists.
So I will explain more my issue.

I have a function that assigne a Database field of type Datetime with a value from TDateTimePicker (not TDBDateTimePicker)
the function is
Code: Pascal  [Select]
  1. function fQueryAssignVal( oQuery: TQuery;  // the query
  2.     sFName: String; // field name on DB
  3.     fDataType: ftDataType, // type of field, ftstring ....
  4.     fValue: Variant  // Value that will be Assigned.
  5.   ); boolean;
  6. begin
  7.   if (fDataType in [ftDate]) then
  8.   begin
  9.     if ( TDateTime(psValue) <> TDateTime(NullDate) ) then
  10.       psValue := TDate(VarToDateTime(psValue))
  11.     else psValue := Null;
  12.     if (psValue = 0) then
  13.        psValue := NULL;
  14.     //if ( VarToDateTime(psValue) <> NullDate )
  15.     //   psValue:= Trunc(psValue);
  16.   end;
  17.  
  18.  
  19. end;
  20.  
  21. // WHEN CALLING
  22.      // .....  
  23.      fQueryAssignVal( qryPTNS, 'DateNais', ftDate, DtPicker.Date);
  24.     //....
  25.     qryPTNS.Execute;
  26.  
  27.  

if DtPicker Date is not null itworks, but if it is null It gives me Error Conversion.

I do not know what to do really.

Please help.

lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

ASerge

  • Hero Member
  • *****
  • Posts: 1422
Re: Issues with TDateTimePicker
« Reply #4 on: November 19, 2019, 11:31:50 pm »
So I will explain more my issue.
Code: Pascal  [Select]
  1. function DateTimeToVariant(const Value: TDate): Variant;
  2. begin
  3.   if IsNullDate(Value) then
  4.     Result := Null
  5.   else
  6.     Result := Value;
  7. end;