View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001798 | JEDI VCL | 00 JVCL Components | public | 2004-05-26 12:06 | 2004-05-28 01:04 |
Reporter | hamilton | Assigned To | user72 | ||
Priority | normal | Severity | major | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Product Version | |||||
Target Version | Fixed in Version | ||||
Summary | 0001798: JvDBDateTimePicker resets date portion of TDateTime when used as time control and vice verse. | ||||
Description | My application uses TDateTime fields. I am attempting to use 2 JvDBDateTimePickers to represent the date and time portions of these fields separately. The problem is that changing the date resets the time to midnight and changing the time resets the date to 1899. A further complication occurs if the NullText property is used. Using ' ' (the space character) as the NullText results in the controls becoming disabled. Changing the date resets the time to midnight, displays a blank time and disables the time control. Changing the time does almost the same thing, except that the dropdown calendar is still enabled and dates may be set this way. | ||||
Tags | No tags attached. | ||||
|
Here's a proposal: when the field type is ftDateTime, ftTimeStamp we don't clear the "opposite" value but if it is ftDate or ftTime we trunc/frac as appropriate. We could additionally add a boolean property to control this behavior (TrimValue). Anyway, try making the following changes: published property TrimValue:boolean read FTrimValue write FTrimValue default True; end; constructor TJvDBDateTimePicker.Create(AOwner: TComponent); begin ... FTrimValue := True; end; procedure TJvDBDateTimePicker.DataChange(Sender: TObject); begin if FDataLink.Field <> nil then begin if Kind = dtkDate then begin if IsDateAndTimeField then DateTime := FDataLink.Field.AsDateTime else DateTime := Trunc(FDataLink.Field.AsDateTime); end else begin if IsDateAndTimeField then DateTime := FDataLink.Field.AsDateTime else DateTime := Frac(FDataLink.Field.AsDateTime); end; end else if csDesigning in ComponentState then begin DateTime := Now; end; CheckNullValue; end; procedure TJvDBDateTimePicker.KeyDown(var Key: Word; Shift: TShiftState); begin // we still parent code inherited KeyDown(Key, Shift); // Is it Delete key, insert key or shiftstate ... case Key of VK_DELETE: begin FDataLink.Edit; if Kind = dtkDate then begin if IsDateAndTimeField then DateTime := NullDate else DateTime := Trunc(NullDate); end else begin if IsDateAndTimeField then DateTime := NullDate else DateTime := Frac(NullDate); end; CheckNullValue; UpdateData(Self); end; VK_INSERT: if ssShift in Shift then FDataLink.Edit; end; end; procedure TJvDBDateTimePicker.UpdateData(Sender: TObject); begin // update value in datalink with date value in control, not from system if not FDataLink.Editing then Exit; if Kind = dtkDate then begin if Trunc(NullDate) = Trunc(DateTime) then FDataLink.Field.Value := NULL else if IsDateAndTimeField then FDataLink.Field.AsDateTime := DateTime else FDataLink.Field.AsDateTime := Trunc(DateTime); end else begin if Frac(NullDate) = Frac(DateTime) then FDataLink.Field.Value := NULL else if IsDateAndTimeField then FDataLink.Field.AsDateTime := DateTime; else FDataLink.Field.AsDateTime := Frac(DateTime); end; end; function TJvDBDateTimePicker.IsDateAndTimeField: Boolean; begin with FDataLink do Result := (Field <> nil) and (Field.DataType in [ftDateTime, ftTimeStamp]) and not TrimValue; end; |
|
Thanks for the code Peter. I will try it out shortly then get back to you. |
|
The code works perfectly. Cheers! Being pedantic, there are 2 typos that you will pick up when you compile the code: * FTrimValue needs to be declared * There is an extra ';' in UpdateData I think this bugnote can be closed. I did discover two other problems while testing, I will post these as new bugnotes. [Sorry :( ] |
|
So, can you help me come up with a better name than "TrimValue"? |
|
TrimValue is probably as good as it is going to get :) The alternative may be a short sentence! I opened the NullText issue as a separate report. Have a look at what I've said there and let me know if you are still unable to replicate it. |
|
>The alternative may be a short sentence! I was thinking about "RemoveDateOrTimePortionNotUsedBasedOnKindPropertyUnlessDataTypeIsDateTimeOrSQLTimeStamp" but wasn't sure it would be appreciated ;) |
|
> "RemoveDateOrTimePortionNotUsedBasedOnKindPropertyUnlessDataTypeIsDateTimeOrSQLTimeStamp" If variable names were all like that then you wouldn't need to write online help :D |
|
No, but you'd need a 52 inch screen at max resolution to read the code :) |
|
I've updated this part in CVS. Still need to find a solution for the NullText problem, though (0001805) |
Date Modified | Username | Field | Change |
---|---|---|---|
2004-05-26 12:06 | hamilton | New Issue | |
2004-05-27 00:30 |
|
Note Added: 0004369 | |
2004-05-27 00:31 |
|
Status | new => feedback |
2004-05-27 08:46 | hamilton | Note Added: 0004377 | |
2004-05-27 10:10 | hamilton | Note Added: 0004378 | |
2004-05-27 10:41 |
|
Note Added: 0004381 | |
2004-05-27 10:41 |
|
Status | feedback => assigned |
2004-05-27 10:41 |
|
Assigned To | => user72 |
2004-05-27 10:51 | hamilton | Note Added: 0004385 | |
2004-05-27 11:12 |
|
Note Added: 0004389 | |
2004-05-27 12:18 | hamilton | Note Added: 0004396 | |
2004-05-27 12:34 |
|
Note Added: 0004398 | |
2004-05-28 01:04 |
|
Status | assigned => resolved |
2004-05-28 01:04 |
|
Resolution | open => fixed |
2004-05-28 01:04 |
|
Note Added: 0004400 |