mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-17 22:09:28 +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
components/lazcontrols
@ -368,6 +368,14 @@ begin
|
||||
UpdateControl;
|
||||
end;
|
||||
|
||||
procedure TCustomFloatSpinEditEx.SetDisplayMode(AValue: TDisplayMode);
|
||||
begin
|
||||
if FDisplayMode = AValue then Exit;
|
||||
GetValue;
|
||||
FDisplayMode := AValue;
|
||||
UpdateControl;
|
||||
end;
|
||||
|
||||
procedure TCustomFloatSpinEditEx.SetExponentDigits(AValue: Integer);
|
||||
begin
|
||||
if FExponentDigits = AValue then Exit;
|
||||
@ -400,13 +408,6 @@ begin
|
||||
UpdateControl;
|
||||
end;
|
||||
|
||||
procedure TCustomFloatSpinEditEx.SetUseScientificNotation(AValue: Boolean);
|
||||
begin
|
||||
if FUseScientificNotation = AValue then Exit;
|
||||
GetValue;
|
||||
FUseScientificNotation := AValue;
|
||||
UpdateControl;
|
||||
end;
|
||||
|
||||
procedure TCustomFloatSpinEditEx.EditKeyPress(var Key: char);
|
||||
begin
|
||||
@ -472,15 +473,23 @@ var
|
||||
LValue: Double;
|
||||
begin
|
||||
LValue := GetLimitedValue(AValue);
|
||||
if not FUseScientificNotation then
|
||||
Result := FloatToStrF(LValue, ffFixed, 20, DecimalPlaces, FFS)
|
||||
else
|
||||
begin
|
||||
if (Abs(LValue) > Power(10,FExponentialFormatLimitPos)) or
|
||||
(Abs(LValue) < Power(10,FExponentialFormatLimitNeg)) then
|
||||
Result := FloatToStrF(GetLimitedValue(AValue), ffExponent, FPrecision, FExponentDigits, FFS)
|
||||
else
|
||||
case FDisplayMode of
|
||||
dmFixed:
|
||||
begin
|
||||
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;
|
||||
|
||||
@ -523,11 +532,11 @@ begin
|
||||
FFS := DefaultFormatSettings;
|
||||
FFS.DecimalSeparator := DefDecimalSeparator;
|
||||
FDecimals := DefDecimals;
|
||||
FUseScientificNotation := False;
|
||||
FExponentialFormatLimitPos := 6;
|
||||
FExponentialFormatLimitNeg := -6;
|
||||
FPrecision := 6;
|
||||
FExponentDigits := 2;
|
||||
FDisplayMode := dmFixed;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -170,25 +170,27 @@ type
|
||||
|
||||
{ TCustomFloatSpinEditEx }
|
||||
|
||||
TDisplayMode = (dmFixed, dmScientific, dmAuto);
|
||||
|
||||
TCustomFloatSpinEditEx = class(specialize TSpinEditExBase<Double>)
|
||||
private const
|
||||
DefDecimals = 2;
|
||||
DefDecimalSeparator = '.';
|
||||
private
|
||||
FDecimals: Integer;
|
||||
FDisplayMode: TDisplayMode;
|
||||
FExponentDigits: Integer;
|
||||
FExponentialFormatLimitNeg: Integer;
|
||||
FExponentialFormatLimitPos: Integer;
|
||||
FFS: TFormatSettings;
|
||||
FPrecision: Integer;
|
||||
FUseScientificNotation: Boolean;
|
||||
function GetDecimalSeparator: Char;
|
||||
procedure SetDecimalSeparator(AValue: Char);
|
||||
procedure SetDisplayMode(AValue: TDisplayMode);
|
||||
procedure SetExponentDigits(AValue: Integer);
|
||||
procedure SetExponentialFormatLimitNeg(AValue: Integer);
|
||||
procedure SetExponentialFormatLimitPos(AValue: Integer);
|
||||
procedure SetPrecision(AValue: Integer);
|
||||
procedure SetUseScientificNotation(AValue: Boolean);
|
||||
protected
|
||||
procedure EditKeyPress(var Key: char); override;
|
||||
function TextIsNumber(const S: String; out ANumber: Double): Boolean; override;
|
||||
@ -201,7 +203,7 @@ type
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
property DecimalSeparator: Char read GetDecimalSeparator write SetDecimalSeparator default DefDecimalSeparator;
|
||||
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 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
|
||||
|
Loading…
Reference in New Issue
Block a user