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);
|
procedure TJCurrencyEdit.setValue(const AValue: currency);
|
||||||
begin
|
begin
|
||||||
theValue := scaleTo(AValue, fDecimals);
|
if fDecimals > 0 then
|
||||||
|
theValue := scaleTo(AValue, fDecimals)
|
||||||
|
else
|
||||||
|
theValue := AValue;
|
||||||
formatInput;
|
formatInput;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -194,7 +197,8 @@ begin
|
|||||||
ShowMessage(Text + ' no es un valor válido');
|
ShowMessage(Text + ' no es un valor válido');
|
||||||
SetFocus;
|
SetFocus;
|
||||||
end;
|
end;
|
||||||
theValue := scaleTo(theValue, fDecimals);
|
if fDecimals > 0 then
|
||||||
|
theValue := scaleTo(theValue, fDecimals);
|
||||||
formatInput;
|
formatInput;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -206,8 +210,6 @@ begin
|
|||||||
key := #0;
|
key := #0;
|
||||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||||
Key := #0;
|
Key := #0;
|
||||||
if (Key = DecimalSeparator) and (fDecimals = 0) then
|
|
||||||
Key := #0;
|
|
||||||
inherited KeyPress(Key);
|
inherited KeyPress(Key);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ end;
|
|||||||
|
|
||||||
procedure TJDBCurrencyEdit.setDecimals(AValue: integer);
|
procedure TJDBCurrencyEdit.setDecimals(AValue: integer);
|
||||||
begin
|
begin
|
||||||
if AValue >= 0 then
|
if (AValue >= 0) and (AValue < 5) then
|
||||||
fDecimales := AValue;
|
fDecimales := AValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -183,9 +183,10 @@ begin
|
|||||||
if IsValidCurrency(Text) then
|
if IsValidCurrency(Text) then
|
||||||
begin
|
begin
|
||||||
theValue := StrToCurr(Text);
|
theValue := StrToCurr(Text);
|
||||||
theValue := ScaleTo(theValue, fDecimales);
|
if fDecimales > 0 then
|
||||||
|
theValue := ScaleTo(theValue, fDecimales);
|
||||||
Text := CurrToStr(theValue);
|
Text := CurrToStr(theValue);
|
||||||
FDataLink.Field.Text := Text;
|
FDataLink.Field.Value := theValue;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -348,8 +349,6 @@ begin
|
|||||||
key := #0;
|
key := #0;
|
||||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||||
Key := #0;
|
Key := #0;
|
||||||
if (Key = DecimalSeparator) and (fDecimales = 0) then
|
|
||||||
Key := #0;
|
|
||||||
|
|
||||||
if (Key <> #0) and (not IsReadOnly) then
|
if (Key <> #0) and (not IsReadOnly) then
|
||||||
FDatalink.Edit;
|
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;
|
unit JDBFloatEdit;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
@ -165,9 +182,10 @@ begin
|
|||||||
if IsValidFloat(Text) then
|
if IsValidFloat(Text) then
|
||||||
begin
|
begin
|
||||||
theValue := StrToFloat(Text);
|
theValue := StrToFloat(Text);
|
||||||
theValue := ScaleTo(theValue, fDecimales);
|
if fDecimales > 0 then
|
||||||
Text := FloatToStr(theValue);
|
theValue := ScaleTo(theValue, fDecimales);
|
||||||
FDataLink.Field.Text := Text;
|
Text := FloatToStr(theValue);
|
||||||
|
FDataLink.Field.Value := theValue;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -271,8 +289,7 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJDBFloatEdit.ScaleTo(const AValue: double;
|
function TJDBFloatEdit.ScaleTo(const AValue: double; const NDecimals: integer): double;
|
||||||
const NDecimals: integer): double;
|
|
||||||
begin
|
begin
|
||||||
Result := round(AValue * power(10, NDecimals)) / power(10, NDecimals);
|
Result := round(AValue * power(10, NDecimals)) / power(10, NDecimals);
|
||||||
end;
|
end;
|
||||||
@ -330,8 +347,6 @@ begin
|
|||||||
key := #0;
|
key := #0;
|
||||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||||
Key := #0;
|
Key := #0;
|
||||||
if (Key = DecimalSeparator) and (fDecimales = 0) then
|
|
||||||
Key := #0;
|
|
||||||
|
|
||||||
if (Key <> #0) and (not IsReadOnly) then
|
if (Key <> #0) and (not IsReadOnly) then
|
||||||
FDatalink.Edit;
|
FDatalink.Edit;
|
||||||
|
@ -164,7 +164,7 @@ end;
|
|||||||
|
|
||||||
procedure TJDBLabeledCurrencyEdit.setDecimals(AValue: integer);
|
procedure TJDBLabeledCurrencyEdit.setDecimals(AValue: integer);
|
||||||
begin
|
begin
|
||||||
if AValue >= 0 then
|
if (AValue >= 0) and (AValue < 5) then
|
||||||
fDecimales := AValue;
|
fDecimales := AValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -178,9 +178,10 @@ begin
|
|||||||
if IsValidCurrency(Text) then
|
if IsValidCurrency(Text) then
|
||||||
begin
|
begin
|
||||||
theValue := StrToCurr(Text);
|
theValue := StrToCurr(Text);
|
||||||
theValue := ScaleTo(theValue, fDecimales);
|
if fDecimales > 0 then
|
||||||
|
theValue := ScaleTo(theValue, fDecimales);
|
||||||
Text := CurrToStr(theValue);
|
Text := CurrToStr(theValue);
|
||||||
FDataLink.Field.Text := Text;
|
FDataLink.Field.Value := theValue;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -344,8 +345,6 @@ begin
|
|||||||
key := #0;
|
key := #0;
|
||||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||||
Key := #0;
|
Key := #0;
|
||||||
if (Key = DecimalSeparator) and (fDecimales = 0) then
|
|
||||||
Key := #0;
|
|
||||||
|
|
||||||
if (Key <> #0) and (not IsReadOnly) then
|
if (Key <> #0) and (not IsReadOnly) then
|
||||||
FDatalink.Edit;
|
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;
|
unit JDBLabeledFloatEdit;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
@ -157,9 +174,10 @@ begin
|
|||||||
if IsValidFloat(Text) then
|
if IsValidFloat(Text) then
|
||||||
begin
|
begin
|
||||||
theValue := StrToFloat(Text);
|
theValue := StrToFloat(Text);
|
||||||
theValue := ScaleTo(theValue, fDecimales);
|
if fDecimales > 0 then
|
||||||
|
theValue := ScaleTo(theValue, fDecimales);
|
||||||
Text := FloatToStr(theValue);
|
Text := FloatToStr(theValue);
|
||||||
FDataLink.Field.Text := Text;
|
FDataLink.Field.Value := theValue;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -323,9 +341,6 @@ begin
|
|||||||
key := #0;
|
key := #0;
|
||||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||||
Key := #0;
|
Key := #0;
|
||||||
if (Key = DecimalSeparator) and (fDecimales = 0) then
|
|
||||||
Key := #0;
|
|
||||||
|
|
||||||
if (Key <> #0) and (not IsReadOnly) then
|
if (Key <> #0) and (not IsReadOnly) then
|
||||||
FDatalink.Edit;
|
FDatalink.Edit;
|
||||||
inherited KeyPress(Key);
|
inherited KeyPress(Key);
|
||||||
|
@ -171,7 +171,10 @@ end;
|
|||||||
|
|
||||||
procedure TJFloatEdit.setValue(const AValue: double);
|
procedure TJFloatEdit.setValue(const AValue: double);
|
||||||
begin
|
begin
|
||||||
theValue := scaleTo(AValue, fDecimals);
|
if fDecimals > 0 then
|
||||||
|
theValue := scaleTo(AValue, fDecimals)
|
||||||
|
else
|
||||||
|
theValue := AValue;
|
||||||
formatInput;
|
formatInput;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -192,7 +195,8 @@ begin
|
|||||||
ShowMessage(Text + ' no es un valor válido');
|
ShowMessage(Text + ' no es un valor válido');
|
||||||
SetFocus;
|
SetFocus;
|
||||||
end;
|
end;
|
||||||
theValue := scaleTo(theValue, fDecimals);
|
if fDecimals > 0 then
|
||||||
|
theValue := scaleTo(theValue, fDecimals);
|
||||||
formatInput;
|
formatInput;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -204,8 +208,6 @@ begin
|
|||||||
key := #0;
|
key := #0;
|
||||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||||
Key := #0;
|
Key := #0;
|
||||||
if (Key = DecimalSeparator) and (fDecimals = 0) then
|
|
||||||
Key := #0;
|
|
||||||
inherited KeyPress(Key);
|
inherited KeyPress(Key);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -169,7 +169,10 @@ end;
|
|||||||
|
|
||||||
procedure TJLabeledCurrencyEdit.setValue(const AValue: currency);
|
procedure TJLabeledCurrencyEdit.setValue(const AValue: currency);
|
||||||
begin
|
begin
|
||||||
theValue := scaleTo(AValue, fDecimals);
|
if fDecimals > 0 then
|
||||||
|
theValue := scaleTo(AValue, fDecimals)
|
||||||
|
else
|
||||||
|
theValue := AValue;
|
||||||
formatInput;
|
formatInput;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -190,7 +193,8 @@ begin
|
|||||||
ShowMessage(Text + ' no es un valor válido');
|
ShowMessage(Text + ' no es un valor válido');
|
||||||
SetFocus;
|
SetFocus;
|
||||||
end;
|
end;
|
||||||
theValue := scaleTo(theValue, fDecimals);
|
if fDecimals > 0 then
|
||||||
|
theValue := scaleTo(theValue, fDecimals);
|
||||||
formatInput;
|
formatInput;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -167,7 +167,10 @@ end;
|
|||||||
|
|
||||||
procedure TJLabeledFloatEdit.setValue(const AValue: double);
|
procedure TJLabeledFloatEdit.setValue(const AValue: double);
|
||||||
begin
|
begin
|
||||||
theValue := scaleTo(AValue, fDecimals);
|
if fDecimals > 0 then
|
||||||
|
theValue := scaleTo(AValue, fDecimals)
|
||||||
|
else
|
||||||
|
theValue := AValue;
|
||||||
formatInput;
|
formatInput;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -188,7 +191,8 @@ begin
|
|||||||
ShowMessage(Text + ' no es un valor válido');
|
ShowMessage(Text + ' no es un valor válido');
|
||||||
SetFocus;
|
SetFocus;
|
||||||
end;
|
end;
|
||||||
theValue := scaleTo(theValue, fDecimals);
|
if fDecimals > 0 then
|
||||||
|
theValue := scaleTo(theValue, fDecimals);
|
||||||
formatInput;
|
formatInput;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -200,8 +204,6 @@ begin
|
|||||||
key := #0;
|
key := #0;
|
||||||
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then
|
||||||
Key := #0;
|
Key := #0;
|
||||||
if (Key = DecimalSeparator) and (fDecimals = 0) then
|
|
||||||
Key := #0;
|
|
||||||
inherited KeyPress(Key);
|
inherited KeyPress(Key);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user