Subject RE: [IBO] Re: Problem with IB_Currency and negatives values
Author Support List
Andrei,

> I still don't understand what is happening. For testing purposes, I
> put one tib_edit and one tib_currency and set datasource and datafield
> of both to the same datasource and field. In TIB_Edit, I can enter the
> value -0.50, it appears in TIB_Currency, but if I click to 'enter' in
> TIB_Currency, the - signal dissapears! When I exit the TIB_Currency
> the - signal appears again!
>
> After your message I set currency property to true, same behavior.

I apologize for the delay in dealing with this bug.

I confirmed it is a problem and it will be fixed in the next release.

In fact, here's the patched method in IB_Controls.pas:

procedure TIB_Currency.FormatCurrentText( ForEditing: boolean ); var
S: string;
D: string;
ST: string;
DF: string;
x: integer;
OldLen,
SelStart: Integer;
{$IFNDEF FPC}
SelStop: Integer;
{$ENDIF}
ds: char;
isNeg: boolean;
begin
ds := {$IFDEF
IBO_VCL2011_OR_GREATER}FormatSettings.{$ENDIF}DecimalSeparator;
FFormatting := True;
try
S := inherited Text;
D := '';
OldLen := {ibo}Length(S);
{$IFNDEF FPC}
{ TODO -cFPCcheck : TCustomMaskEdit.GetSel is currently private }
if HandleAllocated then
GetSel( SelStart, SelStop ); // repositions cursor to the rightmost
position {$ENDIF}
DF := SysDisplayFormat( ForEditing );
x := {ibo}Pos(ds, S);
if x > 0 then
begin
D := {ibo}Copy( S, x, ({ibo}Length(S) - x) + 1);
S := Trim( {ibo}Copy( S, 1, x - 1 ));
if FDecimalPlaces = 0 then
D := ''
else
D := {ibo}Copy(D, 1, (FDecimalPlaces + 1));
end;
IsNeg := ( S <> '' ) and ( s[1] = '-' );
if IsNeg then
Delete( S, 1, 1 );
if (S <> '') then
begin
try
ST := TextToValText( s );
if CheckCurrencyOverRange( ST ) then
begin
// excessive number of digits!
ST := {ibo}Copy(ST, 1, {ibo}Length(ST)-1);
MessageBeep(0);
end;
if ST <> '' then
begin
x := Pos(ds,DF);
if x > 0 then
S := FormatFloat( Copy( DF, 1, x-1 ), StrToFloat( ST ))
else
S := FormatFloat( DF, StrToFloat( ST ));
end
else
S := '';
except
S := '';
end;
end;
if (S = '') and
(D <> '') then
S := '0';
S := S + D;
if IsNeg then
S := '-' + S;
inherited Text := S;
if HandleAllocated and (GetFocus = Handle) and
not (csDesigning in ComponentState) then
begin
Inc( SelStart, {ibo}Length(S) - OldLen );
SetCursor( SelStart );
end;
finally
FFormatting := False;
end;
end;

Thanks,
Jason