Show: Delphi C++
Display Preferences

E2221 $WEAKPACKAGEUNIT '%s' cannot have initialization or finalization code (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Error and Warning Messages (Delphi)

A unit which has been flagged with the $weakpackageunit directive cannot contain initialization or finalization code, nor can it contain global data. The reason for this is that multiple copies of the same weakly packaged units can appear in an application, and then referring to the data for that unit becomes and ambiguous proposition. This ambiguity is furthered when dynamically loaded packages are used in your applications.

unit yamadama;
    Title : String;

  Title := 'Tiny Calc';

In the above example, there are two problems: Title is a global variable, and Title is initialized in the initialization section of the unit.

There are only two alternatives: either remove the $weakpackageunit directive from the unit, or remove all global data, initialization and finalization code.

Personal tools
In other languages
Previous Versions