User Changes 2.2.4

From Lazarus wiki
Revision as of 09:43, 23 April 2009 by Jonas (talk | contribs) (→‎Executing external programs using TProces: -- fixed some small language errors)
Jump to navigationJump to search

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.

All Unix-based systems

Executing external programs using TProcess

  • Old behaviour: When TProcess was used to execute a program and no explicit path to the executable was given, TProcess searched for the executable in the current directory, and only if it was not found there it looked in the system path.
  • New behaviour: On all Unix-based systems, TProcess will not search for the executable in the current directory anymore, unless the current directory is in the system path.
  • Example: When you use TProcess to execute 'ls' and there is an 'ls' executable in both the current directory and in '/bin/', then programs compiled with FPC 2.2.2 will execute './ls' (thus in the current directory). Programs compiled with FPC 2.2.4 will run '/bin/ls' instead.
  • Reason: Security. Unix-users don't expect that files in the current directory are executed in favour of those in the system path.
  • Remedy: If you really want to execute an executable in the current directory, use './exec-name' as executable name.

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.