You've already forked lazarus-ccr
Change ScaleTo criteria
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2027 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -173,7 +173,10 @@ end;
|
||||
|
||||
procedure TJCurrencyEdit.setValue(const AValue: currency);
|
||||
begin
|
||||
theValue := scaleTo(AValue, fDecimals);
|
||||
if fDecimals > 0 then
|
||||
theValue := scaleTo(AValue, fDecimals)
|
||||
else
|
||||
theValue := AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
@ -194,7 +197,8 @@ begin
|
||||
ShowMessage(Text + ' no es un valor válido');
|
||||
SetFocus;
|
||||
end;
|
||||
theValue := scaleTo(theValue, fDecimals);
|
||||
if fDecimals > 0 then
|
||||
theValue := scaleTo(theValue, fDecimals);
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
@ -206,8 +210,6 @@ begin
|
||||
key := #0;
|
||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||
Key := #0;
|
||||
if (Key = DecimalSeparator) and (fDecimals = 0) then
|
||||
Key := #0;
|
||||
inherited KeyPress(Key);
|
||||
end;
|
||||
|
||||
|
@ -169,7 +169,7 @@ end;
|
||||
|
||||
procedure TJDBCurrencyEdit.setDecimals(AValue: integer);
|
||||
begin
|
||||
if AValue >= 0 then
|
||||
if (AValue >= 0) and (AValue < 5) then
|
||||
fDecimales := AValue;
|
||||
end;
|
||||
|
||||
@ -183,9 +183,10 @@ begin
|
||||
if IsValidCurrency(Text) then
|
||||
begin
|
||||
theValue := StrToCurr(Text);
|
||||
theValue := ScaleTo(theValue, fDecimales);
|
||||
if fDecimales > 0 then
|
||||
theValue := ScaleTo(theValue, fDecimales);
|
||||
Text := CurrToStr(theValue);
|
||||
FDataLink.Field.Text := Text;
|
||||
FDataLink.Field.Value := theValue;
|
||||
end
|
||||
else
|
||||
begin
|
||||
@ -348,8 +349,6 @@ begin
|
||||
key := #0;
|
||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||
Key := #0;
|
||||
if (Key = DecimalSeparator) and (fDecimales = 0) then
|
||||
Key := #0;
|
||||
|
||||
if (Key <> #0) and (not IsReadOnly) then
|
||||
FDatalink.Edit;
|
||||
|
@ -1,3 +1,20 @@
|
||||
{ JDBFloatEdit
|
||||
|
||||
Copyright (C) 2011 Julio Jiménez Borreguero
|
||||
Contact: jujibo at gmail dot com
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it
|
||||
under the same terms as the Lazarus Component Library (LCL)
|
||||
|
||||
See the file license-jujiboutils.txt and COPYING.LGPL, included in this distribution,
|
||||
for details about the license.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
}
|
||||
|
||||
unit JDBFloatEdit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
@ -165,9 +182,10 @@ begin
|
||||
if IsValidFloat(Text) then
|
||||
begin
|
||||
theValue := StrToFloat(Text);
|
||||
theValue := ScaleTo(theValue, fDecimales);
|
||||
Text := FloatToStr(theValue);
|
||||
FDataLink.Field.Text := Text;
|
||||
if fDecimales > 0 then
|
||||
theValue := ScaleTo(theValue, fDecimales);
|
||||
Text := FloatToStr(theValue);
|
||||
FDataLink.Field.Value := theValue;
|
||||
end
|
||||
else
|
||||
begin
|
||||
@ -271,8 +289,7 @@ begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TJDBFloatEdit.ScaleTo(const AValue: double;
|
||||
const NDecimals: integer): double;
|
||||
function TJDBFloatEdit.ScaleTo(const AValue: double; const NDecimals: integer): double;
|
||||
begin
|
||||
Result := round(AValue * power(10, NDecimals)) / power(10, NDecimals);
|
||||
end;
|
||||
@ -330,8 +347,6 @@ begin
|
||||
key := #0;
|
||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||
Key := #0;
|
||||
if (Key = DecimalSeparator) and (fDecimales = 0) then
|
||||
Key := #0;
|
||||
|
||||
if (Key <> #0) and (not IsReadOnly) then
|
||||
FDatalink.Edit;
|
||||
|
@ -164,7 +164,7 @@ end;
|
||||
|
||||
procedure TJDBLabeledCurrencyEdit.setDecimals(AValue: integer);
|
||||
begin
|
||||
if AValue >= 0 then
|
||||
if (AValue >= 0) and (AValue < 5) then
|
||||
fDecimales := AValue;
|
||||
end;
|
||||
|
||||
@ -178,9 +178,10 @@ begin
|
||||
if IsValidCurrency(Text) then
|
||||
begin
|
||||
theValue := StrToCurr(Text);
|
||||
theValue := ScaleTo(theValue, fDecimales);
|
||||
if fDecimales > 0 then
|
||||
theValue := ScaleTo(theValue, fDecimales);
|
||||
Text := CurrToStr(theValue);
|
||||
FDataLink.Field.Text := Text;
|
||||
FDataLink.Field.Value := theValue;
|
||||
end
|
||||
else
|
||||
begin
|
||||
@ -344,8 +345,6 @@ begin
|
||||
key := #0;
|
||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||
Key := #0;
|
||||
if (Key = DecimalSeparator) and (fDecimales = 0) then
|
||||
Key := #0;
|
||||
|
||||
if (Key <> #0) and (not IsReadOnly) then
|
||||
FDatalink.Edit;
|
||||
|
@ -1,3 +1,20 @@
|
||||
{ JDBLabeledFloatEdit
|
||||
|
||||
Copyright (C) 2011 Julio Jiménez Borreguero
|
||||
Contact: jujibo at gmail dot com
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it
|
||||
under the same terms as the Lazarus Component Library (LCL)
|
||||
|
||||
See the file license-jujiboutils.txt and COPYING.LGPL, included in this distribution,
|
||||
for details about the license.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
}
|
||||
|
||||
unit JDBLabeledFloatEdit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
@ -157,9 +174,10 @@ begin
|
||||
if IsValidFloat(Text) then
|
||||
begin
|
||||
theValue := StrToFloat(Text);
|
||||
theValue := ScaleTo(theValue, fDecimales);
|
||||
if fDecimales > 0 then
|
||||
theValue := ScaleTo(theValue, fDecimales);
|
||||
Text := FloatToStr(theValue);
|
||||
FDataLink.Field.Text := Text;
|
||||
FDataLink.Field.Value := theValue;
|
||||
end
|
||||
else
|
||||
begin
|
||||
@ -323,9 +341,6 @@ begin
|
||||
key := #0;
|
||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||
Key := #0;
|
||||
if (Key = DecimalSeparator) and (fDecimales = 0) then
|
||||
Key := #0;
|
||||
|
||||
if (Key <> #0) and (not IsReadOnly) then
|
||||
FDatalink.Edit;
|
||||
inherited KeyPress(Key);
|
||||
|
@ -171,7 +171,10 @@ end;
|
||||
|
||||
procedure TJFloatEdit.setValue(const AValue: double);
|
||||
begin
|
||||
theValue := scaleTo(AValue, fDecimals);
|
||||
if fDecimals > 0 then
|
||||
theValue := scaleTo(AValue, fDecimals)
|
||||
else
|
||||
theValue := AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
@ -192,7 +195,8 @@ begin
|
||||
ShowMessage(Text + ' no es un valor válido');
|
||||
SetFocus;
|
||||
end;
|
||||
theValue := scaleTo(theValue, fDecimals);
|
||||
if fDecimals > 0 then
|
||||
theValue := scaleTo(theValue, fDecimals);
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
@ -204,8 +208,6 @@ begin
|
||||
key := #0;
|
||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||
Key := #0;
|
||||
if (Key = DecimalSeparator) and (fDecimals = 0) then
|
||||
Key := #0;
|
||||
inherited KeyPress(Key);
|
||||
end;
|
||||
|
||||
|
@ -169,7 +169,10 @@ end;
|
||||
|
||||
procedure TJLabeledCurrencyEdit.setValue(const AValue: currency);
|
||||
begin
|
||||
theValue := scaleTo(AValue, fDecimals);
|
||||
if fDecimals > 0 then
|
||||
theValue := scaleTo(AValue, fDecimals)
|
||||
else
|
||||
theValue := AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
@ -190,7 +193,8 @@ begin
|
||||
ShowMessage(Text + ' no es un valor válido');
|
||||
SetFocus;
|
||||
end;
|
||||
theValue := scaleTo(theValue, fDecimals);
|
||||
if fDecimals > 0 then
|
||||
theValue := scaleTo(theValue, fDecimals);
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
|
@ -167,7 +167,10 @@ end;
|
||||
|
||||
procedure TJLabeledFloatEdit.setValue(const AValue: double);
|
||||
begin
|
||||
theValue := scaleTo(AValue, fDecimals);
|
||||
if fDecimals > 0 then
|
||||
theValue := scaleTo(AValue, fDecimals)
|
||||
else
|
||||
theValue := AValue;
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
@ -188,7 +191,8 @@ begin
|
||||
ShowMessage(Text + ' no es un valor válido');
|
||||
SetFocus;
|
||||
end;
|
||||
theValue := scaleTo(theValue, fDecimals);
|
||||
if fDecimals > 0 then
|
||||
theValue := scaleTo(theValue, fDecimals);
|
||||
formatInput;
|
||||
end;
|
||||
|
||||
@ -200,8 +204,6 @@ begin
|
||||
key := #0;
|
||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||
Key := #0;
|
||||
if (Key = DecimalSeparator) and (fDecimals = 0) then
|
||||
Key := #0;
|
||||
inherited KeyPress(Key);
|
||||
end;
|
||||
|
||||
|
Reference in New Issue
Block a user