From 4e07f194079d6b4673369cc9c38a76b62616bc2c Mon Sep 17 00:00:00 2001 From: bart <9132501-flyingsheep@users.noreply.gitlab.com> Date: Mon, 10 Aug 2020 21:14:02 +0000 Subject: [PATCH] SpinEx: move StrToValue to the base class. git-svn-id: trunk@63713 - --- components/lazcontrols/spinex.inc | 98 ++++++++++--------------------- components/lazcontrols/spinex.pp | 4 +- 2 files changed, 32 insertions(+), 70 deletions(-) diff --git a/components/lazcontrols/spinex.inc b/components/lazcontrols/spinex.inc index 89ba2e127c..e6efb5bf01 100644 --- a/components/lazcontrols/spinex.inc +++ b/components/lazcontrols/spinex.inc @@ -347,6 +347,37 @@ begin end; end; +function TSpinEditExBase.StrToValue(const S: String): T; +var + Def, N: T; + IsNumber: Boolean; +begin + {$ifdef debugspinex} + debugln(['TSpinEditExBase.StrToValue: S="',S,'"']); + {$endif} + case FNullValueBehaviour of + nvbShowTextHint: Def := FNullValue; + nvbLimitedNullValue: Def := GetLimitedValue(FNullValue); + nvbMinValue: Def := FMinValue; + nvbMaxValue: Def := MaxValue; + nvbInitialValue: Def := FInitialValue; + end; + try + IsNumber := TextIsNumber(S, N); + if IsNumber then + Result := N + else + Result := Def; + if not (FNullValueBehaviour = nvbShowTextHint) then + Result := GetLimitedValue(Result); + except + Result := Def; + end; + {$ifdef debugspinex} + debugln([' Result=',(Result)]); + {$endif} +end; + procedure TSpinEditExBase.FinalizeWnd; begin GetValue; @@ -498,38 +529,6 @@ begin end; end; -function TCustomFloatSpinEditEx.StrToValue(const S: String): Double; -var - Def, D: Double; -begin - {$ifdef debugspinex} - debugln(['TCustomFloatSpinEditEx.StrToValue: S="',S,'"']); - {$endif} - case FNullValueBehaviour of - nvbShowTextHint: Def := FNullValue; - nvbLimitedNullValue: Def := GetLimitedValue(FNullValue); - nvbMinValue: Def := FMinValue; - nvbMaxValue: Def := MaxValue; - nvbInitialValue: Def := FInitialValue; - end; - try - if (FNullValueBehaviour = nvbShowTextHint)then - begin - if TextIsNumber(S, D) - then - Result := D - else - Result := Def; - end - else - Result := GetLimitedValue(StrToFloatDef(S, Def, FFS)); - except - Result := Def; - end; - {$ifdef debugspinex} - debugln([' Result=',Result]); - {$endif} -end; constructor TCustomFloatSpinEditEx.Create(TheOwner: TComponent); begin @@ -645,38 +644,3 @@ begin if (FThousandSeparator <> '') then Result := InsertThousandSeparator(Result, FThousandSeparator); end; - -function TCustomSpinEditEx.StrToValue(const S: String): Int64; -var - Def, N: Int64; -begin - {$ifdef debugspinex} - debugln(['TCustomSpinEditEx.StrToValue: S="',S,'"']); - {$endif} - case FNullValueBehaviour of - nvbShowTextHint: Def := FNullValue; - nvbLimitedNullValue: Def := GetLimitedValue(FNullValue); - nvbMinValue: Def := FMinValue; - nvbMaxValue: Def := MaxValue; - nvbInitialValue: Def := FInitialValue; - end; - try - if (FNullValueBehaviour = nvbShowTextHint)then - begin - if TextIsNumber(RemoveThousandSeparator(S, FThousandSeparator), N) - then - Result := N - else - Result := Def; - end - else - Result := GetLimitedValue(StrToInt64Def(RemoveThousandSeparator(S, FThousandSeparator), Def)); - except - Result := Def; - end; - {$ifdef debugspinex} - debugln([' Result=',(Result)]); - {$endif} -end; - - diff --git a/components/lazcontrols/spinex.pp b/components/lazcontrols/spinex.pp index fee6e9ea7a..1951b4eee5 100644 --- a/components/lazcontrols/spinex.pp +++ b/components/lazcontrols/spinex.pp @@ -157,7 +157,7 @@ type constructor Create(TheOwner: TComponent); override; function GetLimitedValue(const AValue: T): T; virtual; function ValueToStr(const AValue: T): String; virtual; abstract; - function StrToValue(const S: String): T; virtual; abstract; + function StrToValue(const S: String): T; virtual; procedure EditEditingDone; override; public property Increment: T read FIncrement write SetIncrement stored IncrementStored nodefault; @@ -199,7 +199,6 @@ type procedure SetDecimals(ADecimals: Integer); virtual; public function ValueToStr(const AValue: Double): String; override; - function StrToValue(const S: String): Double; override; constructor Create(TheOwner: TComponent); override; property DecimalSeparator: Char read GetDecimalSeparator write SetDecimalSeparator default DefDecimalSeparator; property DecimalPlaces: Integer read FDecimals write SetDecimals default DefDecimals; @@ -306,7 +305,6 @@ type function TextIsNumber(const S: String; out ANumber: Int64): Boolean; override; public function ValueToStr(const AValue: Int64): String; override; - function StrToValue(const S: String): Int64; override; public property Increment default 1; property ThousandSeparator: String read FThousandSeparator write SetThousandSeparator; //string so you can use Utf8