From 1c083034588030e5b42322534b8f8842ee976f5a Mon Sep 17 00:00:00 2001 From: jujibo Date: Sat, 1 Oct 2011 07:29:19 +0000 Subject: [PATCH] Fix: detect properly delete keys. Inerited update only when using standard cell editor git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2055 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/jujiboutils/src/jcontrolutils.pas | 4 -- components/jujiboutils/src/jdbgridcontrol.pas | 2 +- components/jujiboutils/src/jdbgridutils.pas | 39 +++++++++++++++++-- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/components/jujiboutils/src/jcontrolutils.pas b/components/jujiboutils/src/jcontrolutils.pas index d06f816b7..d53aaf396 100644 --- a/components/jujiboutils/src/jcontrolutils.pas +++ b/components/jujiboutils/src/jcontrolutils.pas @@ -242,10 +242,6 @@ function IsValidDateString(const Value: string): boolean; var bTime: TDateTime; begin - //if StrToDateDef(Value, MaxDateTime) = MaxDateTime then - // Result := False - //else - // Result := True; Result:= TryStrToDate(Value, bTime); end; diff --git a/components/jujiboutils/src/jdbgridcontrol.pas b/components/jujiboutils/src/jdbgridcontrol.pas index 1b860b395..e84792274 100644 --- a/components/jujiboutils/src/jdbgridcontrol.pas +++ b/components/jujiboutils/src/jdbgridcontrol.pas @@ -186,7 +186,7 @@ end; procedure TJDBGridControl.UpdateData; begin - if Editor is TJStringCellEditor then + if not(Editor is TJStringCellEditor) then inherited UpdateData; end; diff --git a/components/jujiboutils/src/jdbgridutils.pas b/components/jujiboutils/src/jdbgridutils.pas index a3d50c91c..a36e97622 100644 --- a/components/jujiboutils/src/jdbgridutils.pas +++ b/components/jujiboutils/src/jdbgridutils.pas @@ -341,6 +341,19 @@ end; procedure TJDbGridDateTimeCtrl.OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState); begin + if Key in [VK_DELETE, VK_BACK] then + edited := True; + if Length(CellEditor.Caption) = 0 then + begin + if edited then + begin + Field.DataSet.Edit; + Field.Value := Null; + theValue := 0; + updated := True; + end; + end + else if Length(CellEditor.Caption) <> 0 then if (Key in [VK_RETURN, VK_TAB, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT]) and (not IsValidDateTimeString(NormalizeDateTime(CellEditor.Caption, theValue))) then @@ -488,12 +501,17 @@ end; procedure TJDbGridTimeCtrl.OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState); begin + if Key in [VK_DELETE, VK_BACK] then + edited := True; if Length(CellEditor.Caption) = 0 then begin - Field.DataSet.Edit; - Field.Value := Null; - theValue := 0; - updated := True; + if edited then + begin + Field.DataSet.Edit; + Field.Value := Null; + theValue := 0; + updated := True; + end; end else if (Key in [VK_RETURN, VK_TAB, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT]) and @@ -643,6 +661,19 @@ end; procedure TJDbGridDateCtrl.OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState); begin + if Key in [VK_DELETE, VK_BACK] then + edited := True; + if Length(CellEditor.Caption) = 0 then + begin + if edited then + begin + Field.DataSet.Edit; + Field.Value := Null; + theValue := 0; + updated := True; + end; + end + else if Length(CellEditor.Caption) <> 0 then if (Key in [VK_RETURN, VK_TAB, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT]) and (not IsValidDateString(NormalizeDate(CellEditor.Caption, theValue))) then