[fpc-announce] Support for "class threadvar" sections inside class and record types

Sven Barth pascaldragon at googlemail.com
Sat Jun 23 15:55:10 CEST 2018


Hello together!

Announcing a small feature this time, but some might appreciate it:
FPC now supports the declaration of threadvars inside class and record 
types.

=== code begin ===

{$mode objfpc}
{$modeswitch advancedrecords}

type
   TTestClass = class
   public class threadvar
     Test: LongInt;
   end;

   TTestRecord = record
   public class threadvar
     Test: LongInt;
   end;

begin
   TTestClass.Test := 42;
   TTestRecord.Test := 21;
end.

=== code end ===

A threadvar section is started using "class threadvar" and the "class" 
specifier is required. They are accessed like ordinary class variables 
with the difference that they'll hold different values per thread - the 
same as global threadvars after all.

This feature is Delphi compatible (and was added, because I noticed that 
Delphi supported it and FPC did not 😅)

Regards,
Sven


More information about the fpc-announce mailing list