mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 09:19:22 +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;
|
||||||
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;
|
procedure TSpinEditExBase.FinalizeWnd;
|
||||||
begin
|
begin
|
||||||
GetValue;
|
GetValue;
|
||||||
@ -498,38 +529,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
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);
|
constructor TCustomFloatSpinEditEx.Create(TheOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
@ -645,38 +644,3 @@ begin
|
|||||||
if (FThousandSeparator <> '') then
|
if (FThousandSeparator <> '') then
|
||||||
Result := InsertThousandSeparator(Result, FThousandSeparator);
|
Result := InsertThousandSeparator(Result, FThousandSeparator);
|
||||||
end;
|
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;
|
constructor Create(TheOwner: TComponent); override;
|
||||||
function GetLimitedValue(const AValue: T): T; virtual;
|
function GetLimitedValue(const AValue: T): T; virtual;
|
||||||
function ValueToStr(const AValue: T): String; virtual; abstract;
|
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;
|
procedure EditEditingDone; override;
|
||||||
public
|
public
|
||||||
property Increment: T read FIncrement write SetIncrement stored IncrementStored nodefault;
|
property Increment: T read FIncrement write SetIncrement stored IncrementStored nodefault;
|
||||||
@ -199,7 +199,6 @@ type
|
|||||||
procedure SetDecimals(ADecimals: Integer); virtual;
|
procedure SetDecimals(ADecimals: Integer); virtual;
|
||||||
public
|
public
|
||||||
function ValueToStr(const AValue: Double): String; override;
|
function ValueToStr(const AValue: Double): String; override;
|
||||||
function StrToValue(const S: String): Double; override;
|
|
||||||
constructor Create(TheOwner: TComponent); override;
|
constructor Create(TheOwner: TComponent); override;
|
||||||
property DecimalSeparator: Char read GetDecimalSeparator write SetDecimalSeparator default DefDecimalSeparator;
|
property DecimalSeparator: Char read GetDecimalSeparator write SetDecimalSeparator default DefDecimalSeparator;
|
||||||
property DecimalPlaces: Integer read FDecimals write SetDecimals default DefDecimals;
|
property DecimalPlaces: Integer read FDecimals write SetDecimals default DefDecimals;
|
||||||
@ -306,7 +305,6 @@ type
|
|||||||
function TextIsNumber(const S: String; out ANumber: Int64): Boolean; override;
|
function TextIsNumber(const S: String; out ANumber: Int64): Boolean; override;
|
||||||
public
|
public
|
||||||
function ValueToStr(const AValue: Int64): String; override;
|
function ValueToStr(const AValue: Int64): String; override;
|
||||||
function StrToValue(const S: String): Int64; override;
|
|
||||||
public
|
public
|
||||||
property Increment default 1;
|
property Increment default 1;
|
||||||
property ThousandSeparator: String read FThousandSeparator write SetThousandSeparator; //string so you can use Utf8
|
property ThousandSeparator: String read FThousandSeparator write SetThousandSeparator; //string so you can use Utf8
|
||||||
|
Loading…
Reference in New Issue
Block a user