mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-30 21:22:44 +02:00
SpinEx: move StrToValue to the base class.
git-svn-id: trunk@63713 -
This commit is contained in:
parent
d61c0bfbeb
commit
4e07f19407
@ -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;
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user