From a0a1668847a10f8a11ba0bcb56d259b224c89a6e Mon Sep 17 00:00:00 2001 From: jujibo Date: Fri, 23 Sep 2011 11:30:17 +0000 Subject: [PATCH] Fixed: manage properly Null values for dates and times in TJDBGridControl git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1989 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../jujibo-utils/src/jdbgridcontrol.pas | 27 ++++++++++++------- .../jujibo-utils/src/jdbgridutils.pas | 25 ++++++++++++++--- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/components/jujiboutils/jujibo-utils/src/jdbgridcontrol.pas b/components/jujiboutils/jujibo-utils/src/jdbgridcontrol.pas index 767006616..510a12c64 100644 --- a/components/jujiboutils/jujibo-utils/src/jdbgridcontrol.pas +++ b/components/jujiboutils/jujibo-utils/src/jdbgridcontrol.pas @@ -23,6 +23,7 @@ type { Protected declarations } //procedure SelectEditor; override; function GetDefaultEditor(Column: integer): TWinControl; override; + procedure UpdateData; override; public { Public declarations } constructor Create(TheOwner: TComponent); override; @@ -67,20 +68,28 @@ begin if Result <> nil then begin //aColumn := Columns.Items[Column - 1]; - aField:= GetFieldFromGridColumn(Column); + aField := GetFieldFromGridColumn(Column); //if aColumn <> nil then if aField <> nil then; - //case aColumn.Field.DataType of - case aField.DataType of - ftSmallint, ftInteger: Result := integerDbGridControl.Editor(Self); - ftDate: Result := dateDbGridControl.Editor(Self); - ftTime: Result := timeDbGridControl.Editor(Self); - ftCurrency, ftFloat, ftBCD: Result := doubleDbGridControl.Editor(Self); - // TODO: ftDateTime. strings? - end; + //case aColumn.Field.DataType of + case aField.DataType of + ftSmallint, ftInteger: Result := integerDbGridControl.Editor(Self); + ftDate: Result := dateDbGridControl.Editor(Self); + ftTime: Result := timeDbGridControl.Editor(Self); + ftCurrency, ftFloat, ftBCD: Result := doubleDbGridControl.Editor(Self); + // TODO: ftDateTime. strings? + end; end; end; +procedure TJDBGridControl.UpdateData; +begin + if not (SelectedField.DataType in [ftSmallInt, ftInteger, ftDate, + ftTime, ftCurrency, ftFloat, ftBCD]) then + inherited UpdateData; + // TODO... think more about this +end; + constructor TJDBGridControl.Create(TheOwner: TComponent); begin inherited Create(TheOwner); diff --git a/components/jujiboutils/jujibo-utils/src/jdbgridutils.pas b/components/jujiboutils/jujibo-utils/src/jdbgridutils.pas index ae183c630..8b814dde9 100644 --- a/components/jujiboutils/jujibo-utils/src/jdbgridutils.pas +++ b/components/jujiboutils/jujibo-utils/src/jdbgridutils.pas @@ -151,7 +151,12 @@ procedure TJDbGridTimeCtrl.myEditOnEditingDone(Sender: TObject); begin CellEditor.Caption := NormalizeTime(CellEditor.Caption, theValue); if Length(CellEditor.Caption) = 0 then - theValue := 0 + begin + Field.DataSet.Edit; + Field.Value := Null; + theValue := 0; + updated := True; + end else if IsValidTimeString(CellEditor.Caption) then begin @@ -190,7 +195,14 @@ end; procedure TJDbGridTimeCtrl.OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState); begin - if Length(CellEditor.Caption) <> 0 then + if Length(CellEditor.Caption) = 0 then + begin + Field.DataSet.Edit; + Field.Value := Null; + theValue := 0; + updated := True; + end + else if (Key in [VK_RETURN, VK_TAB, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT]) and (not IsValidTimeString(NormalizeTime(CellEditor.Caption, theValue))) then begin @@ -225,7 +237,7 @@ begin begin theValue := StrToTime(CellEditor.Caption); Field.DataSet.Edit; - Field.AsDateTime:= theValue ; + Field.AsDateTime := theValue; CellEditor.SelectAll; updated := True; end; @@ -283,7 +295,12 @@ procedure TJDbGridDateCtrl.myEditOnEditingDone(Sender: TObject); begin CellEditor.Caption := NormalizeDate(CellEditor.Caption, theValue); if Length(CellEditor.Caption) = 0 then - theValue := 0 + begin + Field.DataSet.Edit; + Field.Value := Null; + theValue := 0; + updated := True; + end else if IsValidDateString(CellEditor.Caption) then begin