[Pas2js] new feature class constructors

Mattias Gaertner nc-gaertnma at netcologne.de
Sun Feb 17 22:18:56 CET 2019


Hi all,

Trunk pas2js now supports class constructors.

Class constructors are called in the initialization section, but only
if the class is actually used in the program.
So they are like better initialization sections.

Here is an example from the sysutils unit:

type
  TFormatSettings = class(TObject)
    class constructor Init;
  end;

class constructor TFormatSettings.Init;
begin
  FormatSettings := TFormatSettings.Create;
end;

Formerly the TFormatSettings.Create statement was in the initialization
section and thus the class was always included, even if no code used it.
Using the class constructor the optimizer can now omit the class
completely.

They work for classes, records, class helpers, record helpers and type helpers.
A class constructor of a helper is only used if a member of the helper
is used.

Class constructors cannot be called directly and can have any name
(Delphi/FPC compatible).

Please test!

Mattias


More information about the Pas2js mailing list