LCL: float spin (ex): fix streaming of Increment and MaxValue properties in FPC trunk. Issue #33567

git-svn-id: trunk@57605 -
This commit is contained in:
ondrej 2018-04-05 10:19:34 +00:00
parent 067144af2d
commit 81bee86e42
4 changed files with 52 additions and 21 deletions

View File

@ -192,6 +192,11 @@ begin
if FUpdatePending then UpdateControl;
end;
function TSpinEditExBase.MaxValueStored: Boolean;
begin
Result := not SameValue(FMaxValue, DefMaxValue);
end;
procedure TSpinEditExBase.EditMouseWheelUp(Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
@ -239,6 +244,11 @@ begin
Result := FValue;
end;
function TSpinEditExBase.IncrementStored: Boolean;
begin
Result := not SameValue(FIncrement, DefIncrement);
end;
function TSpinEditExBase.IsLimited: Boolean;
begin
Result := MaxValue > MinValue;
@ -307,14 +317,12 @@ begin
inherited Create(TheOwner);
FArrowKeys := True;
FIncrement := 1;
FValue := 0;
FMinValue := 0;
FMaxValue := 100;
FIncrement := DefIncrement;
FMaxValue := DefMaxValue;
FUpdatePending := True;
FSettingValue := False;
FNullValueBehaviour := nvbMinValue;
FMinRepeatValue := 100;
FMinRepeatValue := DefMinRepeatValue;
Edit.Alignment := taRightJustify;
@ -465,8 +473,8 @@ constructor TCustomFloatSpinEditEx.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FFS := DefaultFormatSettings;
FFS.DecimalSeparator := '.';
FDecimals := 2;
FFS.DecimalSeparator := DefDecimalSeparator;
FDecimals := DefDecimals;
end;

View File

@ -97,6 +97,10 @@ type
{ TSpinEditExBase }
generic TSpinEditExBase<T> = class(TCustomAbstractGroupedEdit)
private const
DefIncrement = 1;
DefMaxValue = 100;
DefMinRepeatValue = 100;
private
FArrowKeys: Boolean;
FIncrement: T;
@ -121,6 +125,8 @@ type
procedure UpDownChangingEx(Sender: TObject; var {%H-}AllowChange: Boolean;
{%H-}NewValue: SmallInt; Direction: TUpDownDirection);
procedure UpDownClick(Sender: TObject; {%H-}Button: TUDBtnType);
function IncrementStored: Boolean;
function MaxValueStored: Boolean;
protected
function GetBuddyClassType: TControlClass; override;
procedure DoEnter; override;
@ -145,7 +151,7 @@ type
property ArrowKeys: Boolean read FArrowKeys write FArrowKeys default True;
property Edit: TGEEdit read GetEdit;
property UpDown: TUpDown read GetUpDown;
property MinRepeatValue: Byte read FMinRepeatValue write SetMinRepeatValue default 100;
property MinRepeatValue: Byte read FMinRepeatValue write SetMinRepeatValue default DefMinRepeatValue;
public
constructor Create(TheOwner: TComponent); override;
function GetLimitedValue(const AValue: T): T; virtual;
@ -153,9 +159,9 @@ type
function StrToValue(const S: String): T; virtual; abstract;
procedure EditEditingDone; override;
public
property Increment: T read FIncrement write SetIncrement;
property Increment: T read FIncrement write SetIncrement stored IncrementStored nodefault;
property MinValue: T read FMinValue write SetMinValue;
property MaxValue: T read FMaxValue write SetMaxValue;
property MaxValue: T read FMaxValue write SetMaxValue stored MaxValueStored nodefault;
property NullValue: T read GetNullValue write SetNullValue;
property NullValueBehaviour: TNullValueBehaviour read FNullValueBehaviour write FNullValueBehaviour default nvbMinValue;
property Value: T read GetValue write SetValue;
@ -164,6 +170,9 @@ type
{ TCustomFloatSpinEditEx }
TCustomFloatSpinEditEx = class(specialize TSpinEditExBase<Double>)
private const
DefDecimals = 2;
DefDecimalSeparator = '.';
private
FDecimals: Integer;
FFS: TFormatSettings;
@ -179,8 +188,8 @@ type
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 '.';
property DecimalPlaces: Integer read FDecimals write SetDecimals default 2;
property DecimalSeparator: Char read GetDecimalSeparator write SetDecimalSeparator default DefDecimalSeparator;
property DecimalPlaces: Integer read FDecimals write SetDecimals default DefDecimals;
end;

View File

@ -101,6 +101,11 @@ begin
if FUpdatePending then UpdateControl;
end;
function TCustomFloatSpinEdit.MaxValueStored: Boolean;
begin
Result := not SameValue(FMaxValue, DefMaxValue);
end;
procedure TCustomFloatSpinEdit.KeyPress(var Key: char);
{Disallow any key that is not a digit, decimalseparator, + or -
For ease of use translate any decimalpoint or comma to DecimalSeparator
@ -149,6 +154,11 @@ begin
Result := FValue;
end;
function TCustomFloatSpinEdit.IncrementStored: Boolean;
begin
Result := not SameValue(FIncrement, DefIncrement);
end;
procedure TCustomFloatSpinEdit.SetDecimals(ADecimals: Integer);
begin
if FDecimals = ADecimals then Exit;
@ -161,11 +171,9 @@ begin
inherited Create(TheOwner);
FCompStyle := csSpinEdit;
FIncrement := 1;
FDecimals := 2;
FValue := 0;
FMinValue := 0;
FMaxValue := 100;
FIncrement := DefIncrement;
FDecimals := DefDecimals;
FMaxValue := DefMaxValue;
FUpdatePending := True;
FValueChanged := True;

View File

@ -24,12 +24,16 @@ unit Spin;
interface
uses
Types, Classes, Controls, SysUtils, LCLType, LCLProc, ClipBrd, StdCtrls;
Types, Classes, Controls, SysUtils, LCLType, LCLProc, StdCtrls, Math;
type
{ TCustomFloatSpinEdit }
TCustomFloatSpinEdit = class(TCustomEdit)
private const
DefIncrement = 1;
DefDecimals = 2;
DefMaxValue = 100;
private
FIncrement: Double;
FDecimals: Integer;
@ -41,6 +45,8 @@ type
FValueChanged: Boolean;
function GetValue: Double;
procedure UpdateControl;
function MaxValueStored: Boolean;
function IncrementStored: Boolean;
protected
class procedure WSRegisterClass; override;
function RealGetText: TCaption; override;
@ -63,10 +69,10 @@ type
function ValueToStr(const AValue: Double): String; virtual;
function StrToValue(const S: String): Double; virtual;
public
property DecimalPlaces: Integer read FDecimals write SetDecimals default 2;
property Increment: Double read FIncrement write SetIncrement;
property DecimalPlaces: Integer read FDecimals write SetDecimals default DefDecimals;
property Increment: Double read FIncrement write SetIncrement stored IncrementStored nodefault;
property MinValue: Double read FMinValue write SetMinValue;
property MaxValue: Double read FMaxValue write SetMaxValue;
property MaxValue: Double read FMaxValue write SetMaxValue stored MaxValueStored nodefault;
property Value: Double read GetValue write SetValue;
property ValueEmpty: Boolean read FValueEmpty write SetValueEmpty default False;
end;