From 8023e253b0ca8350557287cbb67e63330e306091 Mon Sep 17 00:00:00 2001 From: jujibo Date: Fri, 8 Nov 2013 12:52:19 +0000 Subject: [PATCH] Added: EditFormat property to FloatEdit components git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2834 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../jujiboutils/src/jdblabeledfloatedit.pas | 21 ++++++++++++++++--- .../jujiboutils/src/jlabeledfloatedit.pas | 8 ++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/components/jujiboutils/src/jdblabeledfloatedit.pas b/components/jujiboutils/src/jdblabeledfloatedit.pas index 7e496471c..f7997696d 100644 --- a/components/jujiboutils/src/jdblabeledfloatedit.pas +++ b/components/jujiboutils/src/jdblabeledfloatedit.pas @@ -33,6 +33,7 @@ type TJDBLabeledFloatEdit = class(TCustomLabeledEdit) private fFormat: string; + fEFormat: string; FDataLink: TFieldDataLink; fDecimales: integer; @@ -77,6 +78,7 @@ type published property DisplayFormat: string read getFormat write setFormat; + property EditFormat: string read fEFormat write fEFormat; property DataField: string read GetDataField write SetDataField; property DataSource: TDataSource read GetDataSource write SetDataSource; property Decimals: integer read getDecimals write setDecimals; @@ -149,6 +151,9 @@ begin begin if not Focused then formatInput + else + if Length(EditFormat) > 0 then + Caption := FormatFloat(EditFormat, FDataLink.Field.AsFloat) else Caption := FloatToStr(FDataLink.Field.AsFloat); end @@ -179,7 +184,10 @@ begin theValue := StrToFloat(Text); if fDecimales > 0 then theValue := ScaleTo(theValue, fDecimales); - Text := FloatToStr(theValue); + if Length(EditFormat) > 0 then + Caption := FormatFloat(EditFormat, theValue) + else + Caption := FloatToStr(theValue); FDataLink.Field.Value := theValue; end else @@ -187,7 +195,10 @@ begin if FDataLink.Field <> nil then begin ShowMessage(Format(SInvalidNumber, [Caption])); - Caption := FloatToStr(FDataLink.Field.AsFloat); + if Length(EditFormat) > 0 then + Caption := FormatFloat(EditFormat, FDataLink.Field.AsFloat) + else + Caption := FloatToStr(FDataLink.Field.AsFloat); SelectAll; SetFocus; end; @@ -356,7 +367,10 @@ begin if not FieldIsEditable(Field) or IsReadOnly then exit; if FDataLink.Field <> nil then - Caption := FloatToStr(FDataLink.Field.AsFloat); //FDataLink.Field.AsString; + if Length(EditFormat) > 0 then + Caption := FormatFloat(EditFormat, FDataLink.Field.AsFloat) + else + Caption := FloatToStr(FDataLink.Field.AsFloat); //FDataLink.Field.AsString; inherited DoEnter; end; @@ -369,6 +383,7 @@ begin FDataLink.OnDataChange := @DataChange; FDataLink.OnUpdateData := @UpdateData; FDataLInk.OnActiveChange := @ActiveChange; + fEFormat:= ''; // Set default values //fDecimales := 2; //fFormat := '0.00'; diff --git a/components/jujiboutils/src/jlabeledfloatedit.pas b/components/jujiboutils/src/jlabeledfloatedit.pas index 59c98397b..4d7790420 100644 --- a/components/jujiboutils/src/jlabeledfloatedit.pas +++ b/components/jujiboutils/src/jlabeledfloatedit.pas @@ -34,6 +34,7 @@ type { Private declarations } theValue: double; fFormat: string; + fEFormat: string; fDecimals: integer; function getDecimals: integer; function getFormat: string; @@ -58,6 +59,7 @@ type published { Published declarations } property DisplayFormat: string read getFormat write setFormat; + property EditFormat: string read fEFormat write fEFormat; property Decimals: integer read getDecimals write setDecimals; property Value: double read getValue write setValue; @@ -187,7 +189,10 @@ begin inherited DoEnter; if ReadOnly then exit; - Text := FloatToStr(theValue); + if Length(EditFormat) > 0 then + Text := FormatFloat(EditFormat, theValue) + else + Text := FloatToStr(theValue); SelectAll; end; @@ -223,6 +228,7 @@ constructor TJLabeledFloatEdit.Create(TheOwner: TComponent); begin inherited Create(TheOwner); Text := ''; + fEFormat := ''; fFormat := '#,0.00'; fDecimals := 2; formatInput;