[fpc-devel] Initialize/Finalize management operators and Default intrinsic

Maciej Izak hnb.code at gmail.com
Tue Apr 12 12:35:28 CEST 2016


2016-04-12 12:12 GMT+02:00 Maciej Izak <hnb.code at gmail.com>:

> 2016-04-12 12:01 GMT+02:00 Maciej Izak <hnb.code at gmail.com>:
>
>> To protect our management operators we should declare in System.pp:
>>
>>   FixedAttribute = class(TCustomAttribute); // or
>> SystemInitializedAttribute
>>
>> Now the gSomething from example is declared as:
>>
>> var
>>   [Fixed] gSomething: TSomeType; // fixed can be used only for global
>> variables and for class var/{$J+} const (aka static var)
>>
>
> Of course is still possible to obtain the error, but to achieve this you
> need to really crave this.
>

To to enable the complicated dependencies is possible to allow priority
parameter for Fixed attribute:

  FixedAttribute = class(TCustomAttribute)
    constructor Create(aPriority: Integer = 2000); // can be default set to
2000
  end;

... some module A ...

 var
  [Fixed] gFoo: TSomeType; // default priority is 2000
  [Fixed(10)] gSomething: TSomeType; // lower number means higher priority,
for example, first 1000 can be reserved for internal FPC usage


... somewhere in other module B, gSomething2 has Initialize operator, where
gSomething is used for something...

var
  [Fixed(100)] gSomething2: TSomeType; // has lower priority and will be
initialized after gSomething and finalized before gSomething

-- 
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160412/04acf702/attachment.html>


More information about the fpc-devel mailing list