View Issue Details

IDProjectCategoryView StatusLast Update
0004399JEDI VCL00 JVCL Componentspublic2008-08-12 03:47
ReporterZENsanAssigned Toobones 
PrioritynormalSeveritytweakReproducibilityalways
Status resolvedResolutionfixed 
Product VersionDaily / GIT 
Target VersionFixed in Version3.35 
Summary0004399: TJvDBDateTimePicker sets date to NULL
DescriptionWhen TJvDBDateTimePicker TrimValue = False and mode = time, if user sets time to 0:00:00, them editor sets whole field to NULL, not only time part.
TagsNo tags attached.

Activities

obones

2008-07-15 01:00

administrator   ~0014378

Please provide the zipped sources of a sample application showing this.

2008-07-15 23:45

 

Project1.rar (375,559 bytes)

ZENsan

2008-07-15 23:46

reporter   ~0014383

Simply press Up and Down in Time editor. And date will set to 1899 year.. It works if we set initial value with time. But not works when start value is 0:0:0 for time.

obones

2008-07-23 06:36

administrator   ~0014414

I'm unable to reproduce this. I used your application, clicked the "up" and "down" button in the time field, the date did not change.

ZENsan

2008-07-27 01:49

reporter   ~0014460

How it can happen if I launch the Project1.exe and it happens for, but not happens for you.. Maybe I have wrong Windows version?

2008-07-27 01:49

 

HowToDo.zip (25,685 bytes)

ZENsan

2008-07-27 01:50

reporter   ~0014461

I uploaded HowToDO.zip - printscreens of steps I do so that this happens for attached Project1.rar->Project1.exe. And it doesn't happens in the same way for you???

ZENsan

2008-08-03 23:43

reporter   ~0014472

Last edited: 2008-08-04 05:21

JvDBDateTimePicker.pas FIX:

function TJvDBDateTimePicker.IsDateAndTimeField: Boolean;
begin
  with FDataLink do
    Result := (Field <> nil) and
      (Field.DataType in [ftDateTime {$IFDEF COMPILER6_UP}, ftTimeStamp {$ENDIF}]);
end;

procedure TJvDBDateTimePicker.UpdateData(Sender: TObject);
begin
  // update value in datalink with date value in control, not from system
  // DataLink field might be empty

  if not(Assigned(Field) and FDataLink.Editing) then
    Exit;
  if Kind = dtkDate then
    begin
      if Trunc(NullDate) = Trunc(DateTime) then
        if TrimValue or not IsDateAndTimeField then
          Field.Value := Null
        else
          Field.AsDateTime := Frac(DateTime)
      else
        if TrimValue or not IsDateAndTimeField then
          Field.AsDateTime := Trunc(DateTime)
        else
          Field.AsDateTime := DateTime;
    end
  else
    if IsDateAndTimeField then
      begin
        if Frac(NullDate) = Frac(DateTime) then
          if TrimValue then
            Field.Value := Null
          else
            Field.AsDateTime := Trunc(DateTime)
        else
          if TrimValue then
            Field.AsDateTime := Frac(DateTime)
          else
            Field.AsDateTime := DateTime;
      end;
end;

ZENsan

2008-08-04 05:23

reporter   ~0014475

One moment left, that if Kind is dtkTime and field is not IsDateAndTimeField then I ignore the update...
Maybe there is better solution. But this I think is not bad also.

obones

2008-08-12 00:26

administrator   ~0014493

I'm seeing it just fine now. Evaluating proposed fix...

obones

2008-08-12 00:30

administrator   ~0014494

Why all those changes?
I simply replaced

    if Frac(NullDate) = Frac(DateTime) then
      Field.AsDateTime := Trunc(DateTime)

by

    if Frac(NullDate) = Frac(DateTime) then
      if TrimValue then
        Field.Value := Null
      else
        Field.AsDateTime := Trunc(DateTime)

And it solves the issue.
What do you think?

ZENsan

2008-08-12 02:13

reporter   ~0014497

If it works exactly the same way, then ok.
Does it covers situation when that is not date and time field..?

obones

2008-08-12 02:17

administrator   ~0014498

I don't know. Can you test that?

ZENsan

2008-08-12 02:19

reporter   ~0014499

:)

Can you upload the PAS file for that unit?

2008-08-12 02:27

 

JvDBDateTimePicker.pas (18,921 bytes)

obones

2008-08-12 02:27

administrator   ~0014500

Done

ZENsan

2008-08-12 02:51

reporter   ~0014501

if Kind = dtkDate then
  begin
    if Trunc(NullDate) = Trunc(DateTime) then
      Field.Value := Null
    else
    if IsDateAndTimeField then
      Field.AsDateTime := DateTime
    else
      Field.AsDateTime := Trunc(DateTime);
  end

In your source..
    if Trunc(NullDate) = Trunc(DateTime) then
      Field.Value := Null
will clear the time part if TrimValue is set to true. And this is not correct way.

So I think that this source covers all proprties like TrimValue and also checks for Field datatype (so that it supports time part) so why there is so many checks..

  if (Field = nil) or not FDataLink.Editing then
    Exit;
    
  if Kind = dtkDate then
    begin
      if Trunc(NullDate) = Trunc(DateTime) then
        if TrimValue or not IsDateAndTimeField then
          Field.Value := Null
        else
          Field.AsDateTime := Frac(DateTime)
      else
        if TrimValue or not IsDateAndTimeField then
          Field.AsDateTime := Trunc(DateTime)
        else
          Field.AsDateTime := DateTime;
    end
  else
    if IsDateAndTimeField then
      begin
        if Frac(NullDate) = Frac(DateTime) then
          if TrimValue then
            Field.Value := Null
          else
            Field.AsDateTime := Trunc(DateTime)
        else
          if TrimValue then
            Field.AsDateTime := Frac(DateTime)
          else
            Field.AsDateTime := DateTime;
      end;

And with this code user can understand all the logic of this control.

What you think?

obones

2008-08-12 03:46

administrator   ~0014502

Yep, that's better. This is now in SVN.

Issue History

Date Modified Username Field Change
2008-07-09 08:18 ZENsan New Issue
2008-07-15 01:00 obones Note Added: 0014378
2008-07-15 01:00 obones Status new => feedback
2008-07-15 23:45 ZENsan File Added: Project1.rar
2008-07-15 23:46 ZENsan Note Added: 0014383
2008-07-21 00:24 obones Status feedback => acknowledged
2008-07-23 06:36 obones Status acknowledged => resolved
2008-07-23 06:36 obones Resolution open => unable to reproduce
2008-07-23 06:36 obones Assigned To => obones
2008-07-23 06:36 obones Note Added: 0014414
2008-07-27 01:49 ZENsan Status resolved => feedback
2008-07-27 01:49 ZENsan Resolution unable to reproduce => reopened
2008-07-27 01:49 ZENsan Note Added: 0014460
2008-07-27 01:49 ZENsan File Added: HowToDo.zip
2008-07-27 01:50 ZENsan Note Added: 0014461
2008-08-03 23:43 ZENsan Note Added: 0014472
2008-08-03 23:45 ZENsan Note Edited: 0014472
2008-08-03 23:49 ZENsan Note Edited: 0014472
2008-08-03 23:50 ZENsan Note Edited: 0014472
2008-08-04 05:21 ZENsan Note Edited: 0014472
2008-08-04 05:23 ZENsan Note Added: 0014475
2008-08-12 00:26 obones Note Added: 0014493
2008-08-12 00:26 obones Status feedback => confirmed
2008-08-12 00:30 obones Note Added: 0014494
2008-08-12 00:30 obones Status confirmed => feedback
2008-08-12 02:13 ZENsan Note Added: 0014497
2008-08-12 02:17 obones Note Added: 0014498
2008-08-12 02:19 ZENsan Note Added: 0014499
2008-08-12 02:27 obones File Added: JvDBDateTimePicker.pas
2008-08-12 02:27 obones Note Added: 0014500
2008-08-12 02:51 ZENsan Note Added: 0014501
2008-08-12 03:46 obones Status feedback => resolved
2008-08-12 03:46 obones Fixed in Version => Daily / SVN
2008-08-12 03:46 obones Resolution reopened => fixed
2008-08-12 03:46 obones Note Added: 0014502