Subject | Addition: TIB_ColumnNumeric.Get/SetAsInteger |
---|---|
Author | Jeroen W. Pluimers |
Post date | 2000-12-04T19:26:48Z |
Jason,
To make it easier (i.e. have less exceptions) I added the following two
functions to TIB_ColumnNumberic:
function GetAsInteger: integer; override; // ##jp: for SpinEdit
procedure SetAsInteger( const NewValue: integer ); override; // ##jp: for
SpinEdit
function TIB_ColumnNumeric.GetAsInteger: integer;
begin
{$IFDEF IBO_VCL40_OR_GREATER}
Result := Trunc( Value );
{$ELSE}
Result := Trunc( AsExtended );
{$ENDIF}
end;
procedure TIB_ColumnNumeric.SetAsInteger( const NewValue: integer);
begin
{$IFDEF IBO_VCL40_OR_GREATER}
Value := NewValue;
{$ELSE}
AsExtended := NewValue;
{$ENDIF}
end;
Especially on non-US regional settings that have a decimal separator other
than a dot (.), using a SpinEdit with a Numeric column, you get many
exceptions indicating the expected integer is not a number. Of course this
is handled by the try/except block in TIB_Column.GetAsInteger, but
exceptions are very CPU expensive (since they should be exceptionoal). The
fix above will prevent these exceptions, and also optimize the AsInteger (In
GetAsInteger a Trunc is much faster than a FormatFloat/StrToInt combination,
similar performance increasment for the SetAsInteger).
Jeroen W. Pluimers
Consultant at All I M
http://www.all-im.com
To make it easier (i.e. have less exceptions) I added the following two
functions to TIB_ColumnNumberic:
function GetAsInteger: integer; override; // ##jp: for SpinEdit
procedure SetAsInteger( const NewValue: integer ); override; // ##jp: for
SpinEdit
function TIB_ColumnNumeric.GetAsInteger: integer;
begin
{$IFDEF IBO_VCL40_OR_GREATER}
Result := Trunc( Value );
{$ELSE}
Result := Trunc( AsExtended );
{$ENDIF}
end;
procedure TIB_ColumnNumeric.SetAsInteger( const NewValue: integer);
begin
{$IFDEF IBO_VCL40_OR_GREATER}
Value := NewValue;
{$ELSE}
AsExtended := NewValue;
{$ENDIF}
end;
Especially on non-US regional settings that have a decimal separator other
than a dot (.), using a SpinEdit with a Numeric column, you get many
exceptions indicating the expected integer is not a number. Of course this
is handled by the try/except block in TIB_Column.GetAsInteger, but
exceptions are very CPU expensive (since they should be exceptionoal). The
fix above will prevent these exceptions, and also optimize the AsInteger (In
GetAsInteger a Trunc is much faster than a FormatFloat/StrToInt combination,
similar performance increasment for the SetAsInteger).
Jeroen W. Pluimers
Consultant at All I M
http://www.all-im.com