Difference between revisions of "User Changes 2.2.4"

From Lazarus wiki
Jump to navigationJump to search
Line 85: Line 85:
 
</pre>
 
</pre>
 
* '''Reason''': Compatibility with TP/Delphi.
 
* '''Reason''': Compatibility with TP/Delphi.
* '''Remedy''': If you want to use other kinds of rounding, you can use John Herbster's unit attached to [http://bugs.freepascal.org/view.php?id=12687 bug report 12687].
+
* '''Remedy''': If you want to use other kinds of rounding, you can change the rounding mode using ''Math.SetRoundMode()'', or use John Herbster's unit attached to [http://bugs.freepascal.org/view.php?id=12687 bug report 12687].

Revision as of 22:04, 2 February 2009

About this page

Below you can find a list of intentional changes between the the 2.2.2 release and the 2.2.4 release which can change the behaviour of previously working code, along with why these changes were performed and how you can adapt your code if you are affected by them.

All systems

Default property values

  • Old behaviour: Published properties without a specified default were not streamed under certain circumstances.
  • New behaviour: Such properties are now treated as if they had nodefault specified. This means that some extra properties will now be streamed in such cases:
    • Boolean fields with the value false
    • Enumerated types with the ordinal value 0
  • Example:

<delphi> type

 tenum = (ea,eb,ec);
 tc = class
  private
   fmybool: boolean;
   fenum: tenum;
  published
   property mybool: boolean read fmybool write fmybool;
   property enum: tenum read fenum write fenum;
 end;

var

 c: tc;

begin

 c:=tc.create;
 // write c to a stream

end. </delphi> In earlier versions, mybool nor enum would be written to the stream in this case, while now they will be.

  • Reason: Delphi compatibility.
  • Remedy: Explicitly specify default values as follows

<delphi> type

 tenum = (ea,eb,ec);
 tc = class
  private
   fmybool: boolean;
   fenum: tenum;
  published
   property mybool: boolean read fmybool write fmybool default false;
   property enum: tenum read fenum write fenum default ea;
 end;

</delphi>

db unit: TField*.*Size type

  • Old behaviour: TFieldDef.Size, TField.Size and TField.DataSize were defined as word.
  • New behaviour: TFieldDef.Size, TField.Size and TField.DataSize are defined as integers. This also means that definition of the corresponding methods has changed.
  • Example: The following definitions of methods are changed:
    • constructor TFieldDef.Create(AOwner: TFieldDefs; const AName: string; ADataType: TFieldType; ASize: Integer; ARequired: Boolean; AFieldNo: Longint)
    • procedure TFieldDef.SetSize(const AValue: integer);
    • function TField.GetDataSize: integer;
    • procedure TField.SetSize(AValue: integer);
  • Reason: Delphi compatibility.
  • Remedy: Change the definition of these properties in your methods that override one of the methods above from word to integer.

Non-x86 and non-linux/ppc64 systems

Floating point rounding

  • Old behaviour: On these platforms, the round() function always rounded to the nearest integer, halfway away from zero.
  • New behaviour: By default, round() now performs banker's rounding (round-to-nearest, halfway to even). If the rounding mode is changed using the Math unit's SetRoundMode() function, the round() function now honours this change.
  • Example:

<delphi> begin

 write(round(-2.5),' ');
 write(round(-1.5),' ');
 write(round(-0.5),' ');
 write(round(0.5),' ');
 write(round(1.5),' ');
 writeln(round(2.5));

end. </delphi> The above program used to print:

-3 -2 -1 1 2 3

Now it will print:

-2 -2 0 0 2 2
  • Reason: Compatibility with TP/Delphi.
  • Remedy: If you want to use other kinds of rounding, you can change the rounding mode using Math.SetRoundMode(), or use John Herbster's unit attached to bug report 12687.