mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-19 00:19:26 +02:00
LazControls: implement property DisplayMode for TFloatSpinEditEx. Remove property UseScientificNotation. As proposed by wp.
git-svn-id: trunk@63705 -
This commit is contained in:
parent
acc57c654f
commit
fabfd9c5f0
@ -368,6 +368,14 @@ begin
|
|||||||
UpdateControl;
|
UpdateControl;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomFloatSpinEditEx.SetDisplayMode(AValue: TDisplayMode);
|
||||||
|
begin
|
||||||
|
if FDisplayMode = AValue then Exit;
|
||||||
|
GetValue;
|
||||||
|
FDisplayMode := AValue;
|
||||||
|
UpdateControl;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomFloatSpinEditEx.SetExponentDigits(AValue: Integer);
|
procedure TCustomFloatSpinEditEx.SetExponentDigits(AValue: Integer);
|
||||||
begin
|
begin
|
||||||
if FExponentDigits = AValue then Exit;
|
if FExponentDigits = AValue then Exit;
|
||||||
@ -400,13 +408,6 @@ begin
|
|||||||
UpdateControl;
|
UpdateControl;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomFloatSpinEditEx.SetUseScientificNotation(AValue: Boolean);
|
|
||||||
begin
|
|
||||||
if FUseScientificNotation = AValue then Exit;
|
|
||||||
GetValue;
|
|
||||||
FUseScientificNotation := AValue;
|
|
||||||
UpdateControl;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TCustomFloatSpinEditEx.EditKeyPress(var Key: char);
|
procedure TCustomFloatSpinEditEx.EditKeyPress(var Key: char);
|
||||||
begin
|
begin
|
||||||
@ -472,15 +473,23 @@ var
|
|||||||
LValue: Double;
|
LValue: Double;
|
||||||
begin
|
begin
|
||||||
LValue := GetLimitedValue(AValue);
|
LValue := GetLimitedValue(AValue);
|
||||||
if not FUseScientificNotation then
|
case FDisplayMode of
|
||||||
Result := FloatToStrF(LValue, ffFixed, 20, DecimalPlaces, FFS)
|
dmFixed:
|
||||||
else
|
begin
|
||||||
begin
|
|
||||||
if (Abs(LValue) > Power(10,FExponentialFormatLimitPos)) or
|
|
||||||
(Abs(LValue) < Power(10,FExponentialFormatLimitNeg)) then
|
|
||||||
Result := FloatToStrF(GetLimitedValue(AValue), ffExponent, FPrecision, FExponentDigits, FFS)
|
|
||||||
else
|
|
||||||
Result := FloatToStrF(LValue, ffFixed, 20, DecimalPlaces, FFS)
|
Result := FloatToStrF(LValue, ffFixed, 20, DecimalPlaces, FFS)
|
||||||
|
end;
|
||||||
|
dmScientific:
|
||||||
|
begin
|
||||||
|
Result := FloatToStrF(LValue, ffExponent, FPrecision, FExponentDigits, FFS)
|
||||||
|
end;
|
||||||
|
dmAuto:
|
||||||
|
begin
|
||||||
|
if (Abs(LValue) > Power(10,FExponentialFormatLimitPos)) or
|
||||||
|
(Abs(LValue) < Power(10,FExponentialFormatLimitNeg)) then
|
||||||
|
Result := FloatToStrF(LValue, ffExponent, FPrecision, FExponentDigits, FFS)
|
||||||
|
else
|
||||||
|
Result := FloatToStrF(LValue, ffFixed, 20, DecimalPlaces, FFS)
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -523,11 +532,11 @@ begin
|
|||||||
FFS := DefaultFormatSettings;
|
FFS := DefaultFormatSettings;
|
||||||
FFS.DecimalSeparator := DefDecimalSeparator;
|
FFS.DecimalSeparator := DefDecimalSeparator;
|
||||||
FDecimals := DefDecimals;
|
FDecimals := DefDecimals;
|
||||||
FUseScientificNotation := False;
|
|
||||||
FExponentialFormatLimitPos := 6;
|
FExponentialFormatLimitPos := 6;
|
||||||
FExponentialFormatLimitNeg := -6;
|
FExponentialFormatLimitNeg := -6;
|
||||||
FPrecision := 6;
|
FPrecision := 6;
|
||||||
FExponentDigits := 2;
|
FExponentDigits := 2;
|
||||||
|
FDisplayMode := dmFixed;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -170,25 +170,27 @@ type
|
|||||||
|
|
||||||
{ TCustomFloatSpinEditEx }
|
{ TCustomFloatSpinEditEx }
|
||||||
|
|
||||||
|
TDisplayMode = (dmFixed, dmScientific, dmAuto);
|
||||||
|
|
||||||
TCustomFloatSpinEditEx = class(specialize TSpinEditExBase<Double>)
|
TCustomFloatSpinEditEx = class(specialize TSpinEditExBase<Double>)
|
||||||
private const
|
private const
|
||||||
DefDecimals = 2;
|
DefDecimals = 2;
|
||||||
DefDecimalSeparator = '.';
|
DefDecimalSeparator = '.';
|
||||||
private
|
private
|
||||||
FDecimals: Integer;
|
FDecimals: Integer;
|
||||||
|
FDisplayMode: TDisplayMode;
|
||||||
FExponentDigits: Integer;
|
FExponentDigits: Integer;
|
||||||
FExponentialFormatLimitNeg: Integer;
|
FExponentialFormatLimitNeg: Integer;
|
||||||
FExponentialFormatLimitPos: Integer;
|
FExponentialFormatLimitPos: Integer;
|
||||||
FFS: TFormatSettings;
|
FFS: TFormatSettings;
|
||||||
FPrecision: Integer;
|
FPrecision: Integer;
|
||||||
FUseScientificNotation: Boolean;
|
|
||||||
function GetDecimalSeparator: Char;
|
function GetDecimalSeparator: Char;
|
||||||
procedure SetDecimalSeparator(AValue: Char);
|
procedure SetDecimalSeparator(AValue: Char);
|
||||||
|
procedure SetDisplayMode(AValue: TDisplayMode);
|
||||||
procedure SetExponentDigits(AValue: Integer);
|
procedure SetExponentDigits(AValue: Integer);
|
||||||
procedure SetExponentialFormatLimitNeg(AValue: Integer);
|
procedure SetExponentialFormatLimitNeg(AValue: Integer);
|
||||||
procedure SetExponentialFormatLimitPos(AValue: Integer);
|
procedure SetExponentialFormatLimitPos(AValue: Integer);
|
||||||
procedure SetPrecision(AValue: Integer);
|
procedure SetPrecision(AValue: Integer);
|
||||||
procedure SetUseScientificNotation(AValue: Boolean);
|
|
||||||
protected
|
protected
|
||||||
procedure EditKeyPress(var Key: char); override;
|
procedure EditKeyPress(var Key: char); override;
|
||||||
function TextIsNumber(const S: String; out ANumber: Double): Boolean; override;
|
function TextIsNumber(const S: String; out ANumber: Double): Boolean; override;
|
||||||
@ -201,7 +203,7 @@ type
|
|||||||
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;
|
||||||
property UseScientificNotation: Boolean read FUseScientificNotation write SetUseScientificNotation default False;
|
property DisplayMode: TDisplayMode read FDisplayMode write SetDisplayMode default dmFixed;
|
||||||
property ExponentialFormatLimitPos: Integer read FExponentialFormatLimitPos write SetExponentialFormatLimitPos default 6; //used for scientific notation only
|
property ExponentialFormatLimitPos: Integer read FExponentialFormatLimitPos write SetExponentialFormatLimitPos default 6; //used for scientific notation only
|
||||||
property ExponentialFormatLimitNeg: Integer read FExponentialFormatLimitNeg write SetExponentialFormatLimitNeg default -6; //used for scientific notation only
|
property ExponentialFormatLimitNeg: Integer read FExponentialFormatLimitNeg write SetExponentialFormatLimitNeg default -6; //used for scientific notation only
|
||||||
property Precision: Integer read FPrecision write SetPrecision default 6; //used for scientific notation only
|
property Precision: Integer read FPrecision write SetPrecision default 6; //used for scientific notation only
|
||||||
|
Loading…
Reference in New Issue
Block a user