Menu

#6 TCurrencyEdit II

open
nobody
None
5
2002-06-10
2002-06-10
No

The TCurrencyEdit has another flaw. If the
DecimalPlaces value is set to 0, the user is still able to
type in a decimal separator after the last number,
causing the silly value of "0." in the control. I suggest
the following change to the implementation of the
IsValidChar method:

function TCustomNumEdit.IsValidChar(Key: Char):
Boolean;
var
S: string;
SelStart, SelStop, DecPos: Integer;
RetValue: Extended;
begin
Result := False;
S := EditText;
GetSel(SelStart, SelStop);
System.Delete(S, SelStart + 1, SelStop - SelStart);
System.Insert(Key, S, SelStart + 1);
S := TextToValText(S);

{ Begin Dnote modification: Entering decimal separator
not allow when decimalplaces = 0.
Before this condition it was possible to place a
dec.sep. at the end of a number
e.g. '100.'}
if (Key = DecimalSeparator) and (FDecimalPlaces = 0)
then
Exit;
{ End Dnote modification }

DecPos := Pos(DecimalSeparator, S);
if (DecPos > 0) then begin
SelStart := Pos('E', UpperCase(S));
if (SelStart > DecPos) then DecPos := SelStart -
DecPos
else DecPos := Length(S) - DecPos;
if DecPos > Integer(FDecimalPlaces) then Exit;
end;
Result := IsValidFloat(S, RetValue);
if Result and (FMinValue >= 0) and (FMaxValue > 0)
and (RetValue < 0) then
Result := False;
end;

Discussion


Log in to post a comment.