From 0eaf0d46c4dfcec85338bd83e26eda0d4b1c9650 Mon Sep 17 00:00:00 2001 From: jujibo Date: Fri, 8 Nov 2013 15:44:57 +0000 Subject: [PATCH] Added EditFormat property to JDBGridControl git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2835 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/jujiboutils/src/jdbgridcontrol.pas | 9 ++++++--- components/jujiboutils/src/jdbgridutils.pas | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/components/jujiboutils/src/jdbgridcontrol.pas b/components/jujiboutils/src/jdbgridcontrol.pas index 9fa0c13f0..cc72a07df 100644 --- a/components/jujiboutils/src/jdbgridcontrol.pas +++ b/components/jujiboutils/src/jdbgridcontrol.pas @@ -33,6 +33,7 @@ type private fDecimals: integer; fMaxLength: integer; + fEFormat: string; function getDecimals: integer; function getMaxLength: integer; procedure setDecimals(AValue: integer); @@ -40,6 +41,7 @@ type published property Decimals: integer read getDecimals write setDecimals; property MaxLength: integer read getMaxLength write setMaxLength; + property EditFormat: string read fEFormat write fEFormat; end; { TJDBGridColumns } @@ -179,9 +181,11 @@ begin Result := dateTimeDbGridControl.Editor(Self); ftCurrency, ftFloat: Result := - doubleDbGridControl.Editor(Self, Columns[Column - 1].Decimals); + doubleDbGridControl.Editor(Self, Columns[Column - 1].Decimals, + Columns[Column - 1].EditFormat); ftBCD, ftFMTBCD: - Result := doubleDbGridControl.Editor(Self, aField.Size); + Result := doubleDbGridControl.Editor(Self, aField.Size, + Columns[Column - 1].EditFormat); ftString: Result := stringDbGridControl.Editor(Self, Columns[Column - 1].MaxLength); end; @@ -235,4 +239,3 @@ begin end; end. - diff --git a/components/jujiboutils/src/jdbgridutils.pas b/components/jujiboutils/src/jdbgridutils.pas index f4e513990..d37057844 100644 --- a/components/jujiboutils/src/jdbgridutils.pas +++ b/components/jujiboutils/src/jdbgridutils.pas @@ -163,6 +163,7 @@ type updated: boolean; theValue: double; fDecimals: integer; + fEFormat: string; function getDecimals: integer; procedure myEditOnEnter(Sender: TObject); procedure myEditOnEditingDone(Sender: TObject); @@ -177,7 +178,8 @@ type property decimals: integer read getDecimals write setDecimals; constructor Create; destructor Destroy; override; - function Editor(aGrid: TDBGrid; aDecimals: integer = 2): TStringCellEditor; + function Editor(aGrid: TDBGrid; aDecimals: integer = 2; + aEFormat: string = ''): TStringCellEditor; function CanDefocus: boolean; end; @@ -290,8 +292,8 @@ begin if Field.IsNull then Result := '' else - Result := FormatDateTime(ShortDateFormat, Field.AsDateTime) + ' ' + - FormatDateTime(ShortTimeFormat, Field.AsDateTime); + Result := FormatDateTime(ShortDateFormat, Field.AsDateTime) + + ' ' + FormatDateTime(ShortTimeFormat, Field.AsDateTime); end; procedure TJDbGridDateTimeCtrl.myEditEnter(Sender: TObject); @@ -950,7 +952,10 @@ begin if not Assigned(Field) then Abort; CellEditor.BoundsRect := theGrid.SelectedFieldRect; - CellEditor.Text := Field.AsString; + if Length(fEFormat) > 0 then + CellEditor.Text := FormatFloat(fEFormat, Field.AsFloat) + else + CellEditor.Text := Field.AsString; CellEditor.OnKeyPress := @OnKeyPress; // Recuperamos el control :-p CellEditor.OnKeyDown := @OnKeyDown; theValue := Field.AsFloat; @@ -1075,10 +1080,11 @@ begin inherited Destroy; end; -function TJDbGridDoubleCtrl.Editor(aGrid: TDBGrid; - aDecimals: integer): TStringCellEditor; +function TJDbGridDoubleCtrl.Editor(aGrid: TDBGrid; aDecimals: integer; + aEFormat: string): TStringCellEditor; begin decimals := aDecimals; + fEFormat := aEFormat; theGrid := aGrid; Result := CellEditor; end;