Tag: Delphi 10.3 Rio

Some links on the Delphi VolatileAttribute

  

Some links, because I had a hard time finding good documentation on VolatileAttribute (which is the name of the type; you use it as [Volatile] on variables, parameters and fields.
TL;DR

Volatile
The volatile attribute is used to mark fields that are subject to change by different threads, so that code generation does not optimize copying the value in a register or another temporary memory location.
You can use the volatile attribute to mark the following declarations:

Variables (global and local)
Parameters
Fields of a record or a class.

You cannot use the volatile attribute to mark the following declarations:

Type
Procedures, Functions or Methods
Expressions

type
TMyClass = class
private
[volatile] FMyVariable: TMyType;
end;

Searches

[WayBack] Delphi “VolatileAttribute” – Google Search (which gives almost no information as VolatileAttriute is only used as [Volatile]).
[WayBack] Delphi “Volatile attribute” – Google Search (which gives more useful documentation)

Links

[WayBack] Owl’s perspective: DelphiのRTLで定義済の属性 (Google translated):

September 3, 2014

Attributes defined in Delphi RTL

This attribute feature is included in the new RTTI added in Delphi 2010, but there are some attributes that are predefined in RTL, although there are differences depending on the Delphi version. However, there is no descriptive description of these predefined attributes in the help. So I examined it (I have not checked out XE6 / XE7 because I do not have it at hand, but I don’t think there is any difference between XE5 and existing one(I also checked Delphi XE6 / XE7 / XE8 / 10 Seattle / 10.1 Berlin).

System unit

TCustomAttribute
[2010..10.3 Rio] Root class of custom attribute To
define a new attribute, derive from TCustomAttribute
WeakAttribute [Weak]
[XE3..10.3 Rio] Indicates a “weak” reference that prevents situations where ARC cannot destroy objects such as circular references
10 Seattle and earlier NEXTGEN compiler only
Reference: Compiler attributes-RAD Studio
reference : Weak references (automatic reference counting with Delphi mobile compiler)
UnsafeAttribute [Unsafe]
[XE3..10.3 Rio] Prevents ARC destruction when the reference count is 0, such as when an object is created
10 Seattle and earlier NEXTGEN compiler only
Reference: Compiler attributes-RAD Studio
Reference: Unsafe attribute (Delphi Mobile (Automatic reference counting by the compiler)
Reference: Delphi language for mobile development (white paper)
RefAttribute [Ref]
[XE3..10.3 Rio] Force constant parameter to pass by reference
According to help, RefAttribute is a new feature of XE4 , but it can actually be used in XE3.
Reference: Compiler attribute-RAD Studio
Reference: Constant parameter (Parameter ( Delphi))
VolatileAttribute [Volatile]
[XE4..10.3 Rio] Do not perform optimizations that copy values ​​to registers or other temporary memory areas during code generation for fields that may be rewritten by threads
10 Seattle and earlier NEXTGEN compiler only
Reference: Compiler attributes-RAD Studio
Reference: Delphi compiler new attributes (new in Delphi XE4 and C ++ Builder XE4)
Reference: volatile (compiler attribute)
StoredAttribute [Stored]
[XE7..10.3 Rio] See System.Classes.StoredAttribute
HPPGENAttribute [HPPGEN]
[XE8..10.3 Rio] It seems to be information used when generating hpp file for C ++ Builder, but details are unknown
HFAAttribute [HFA]
[XE8..10.3 Rio]There seems to be information on pageId = 86770118 (what it), but details are unknown ( commented with For internal use only. )Override RTTI HFA information generated for record / array types for ARM64 platforms
AlignAttribute [Align]
[10 Seattle..10.3 Rio] It seems to specify the alignment of objects in memory, but there is a comment , For internal use only.

System.Classes unit

ComponentPlatformsAttribute [ComponentPlatforms(<params>)]
[XE2..10.3 Rio] Specify the platform on which the component operates. Specify
the logical sum of the following constants defined in System.Classes for the parameter (Word value).

pidWin32 [XE2..10.3 Rio]
pidWin64 [XE2..10.3 Rio]
pidOSX32 [XE2..10.3 Rio]
pidiOSSimulator32 [10.3 Rio], pidiOSSimulator [XE3..10.3 Rio]
pidAndroid32Arm [10.3 Rio], pidAndroid [XE3..10.3 Rio]
pidLinux32 [XE3..10.3 Rio]
pidiOSDevice32 [XE8..10.3 Rio], pidiOSDevice [XE3..10.3 Rio]
pidLinux64 [XE8..10.3 Rio]
pidWinNX32 [XE3..10.3 Rio]
pidWinIoT32 [XE8..10.3 Rio] (“Embedded IoT (Internet of Things) Windows w / Intel Galileo”)
pidiOSDevice64 [XE8..10.3 Rio]
pidWinARM32 [10.3 Rio], pidWinARM [10 Seattle..10.2 Tokyo]
pidOSX64 [10.1 Berlin..10.3 Rio], pidOSXNX64 [10.1 Berlin..10.2 Tokyo]
pidLinux32Arm [10.1 Berlin..10.3 Rio]
pidLinux64Arm [10.1 Berlin..10.3 Rio]
pidAndroid64Arm [10.3 Rio], pidAndroid64 [10.1 Berlin..10.2 Tokyo]
pidiOSSimulator64 [10.3 Rio]

TDefaultAttributeBase
[XE3..10.3 Rio] DefaultAttribute / NoDefaultAttribute inheritance source
DefaultAttribute [Default(<param>)]
[XE3..10.3 Rio] The property storage specifier default is equivalent
to the default value (Boolean type, AnsiChar type, Char type, Integer type, Cardinal type, Int64 type, UInt64 type, String type, Extended type) Any)
NoDefaultAttribute [NoDefault]
[XE3..10.3 Rio] Property storage specifier equivalent to nodefault
StoredAttribute [Stored(<param>)]
[XE3..XE7] Specify the name of a boolean value (False | True) or storage handler (a method that returns a Boolean value without a Boolean property or parameter) for the specified parameter equivalent to the property storage specifier stored
(Move to System unit after XE8)
ObservableMemberAttribute [ObservableMember(<param>)]
[XE3..10.3 Rio] In LiveBindings compatible component, specify the member name used by LiveBindings component when generating an expression as a parameter

System.JSON.Serializers unit

JsonConverterAttribute[JsonConverter<param>]
[10.3 Rio] Specifying the converter used by TJsonSerializer
JsonIgnoreAttribute[JsonIgnore]
[10.3 Rio] Specifying members to be ignored by TJsonSerializer
JsonNameAttribute[JsonName<param>]
[10.3 Rio] Explicitly specify key name in TJsonSerializer
JsonInAttribute[JsonIn]
[10.3 Rio] When TJsonMemberSerialization.In is specified in the parameter of JsonSerialize attribute, it is serialized / deserialized with TJsonSerializer
JsonObjectHandlingAttribute[JsonObjectHandling<param>]
[10.3 Rio] Specify handling of class type members when deserializing with
TJsonSerializer Specify one of the following values ​​from enumeration type TJsonObjectHandling as a parameter

Auto [10.2 Tokyo..10.3 Rio]
Reuse [10.2 Tokyo..10.3 Rio]
Replace [10.2 Tokyo..10.3 Rio]

JsonObjectOwnership[JsonObjectOwnership<param>]
[10.3 Rio] Specify handling of original instance when class type member is generated when deserializing with
TJsonSerializer Specify one of the following values ​​from enumeration type TJsonObjectOwnership for parameter

Auto [10.2 Tokyo..10.3 Rio]
Owned [10.2 Tokyo..10.3 Rio]
NotOwned [10.2 Tokyo..10.3 Rio]

JsonSerializeAttribute[JsonSerialize<param>]
[10.2 Tokyo..10.3 Rio] Specifying the member to be serialized / deserialized with
TJsonSerializer Specify one of the following values ​​from enumeration type TJsonMemberSerialization for the parameter

Fields [10.2 Tokyo..10.3 Rio]
Public [10.2 Tokyo..10.3 Rio]
In [10.2 Tokyo..10.3 Rio]

Data.DBXJSONReflectUnit ( REST.JsonReflectreplaced with unit in XE5 )

JsonReflect [JsonReflect(<params>)]
[XE..10.3 Rio] TJSONMarshal / TJSONUnMarshal
parameters for customizing the behavior when marshalling / unmarshalling objects in JSON format include converter type, reverter type, interceptor type, population customizer type, marshalling Specifies whether to automatically release generated intermediate objects
JSONBooleanAttribute
[XE..10.3 Rio] Inheritance of JSONMarshalled / JSONOwned
JSONMarshalled [JSONMarshalled(<param>)]
[XE..10.3 Rio] Use parameter (False | True) to specify whether the field or type is subject to marshalling / unmarshalling
JSONOwned [JSONOwned(<param>)]
[XE..10.3 Rio] Specify with parameter (False | True) whether to release the field during unmarshalling

Datasnap.DSAuth unit

TRoleAuth [TRoleAuth(<params>)]
[XE..10.3 Rio] When authenticating with DataSnap, specify the role to allow / deny access to the server method class and server method Specify
the list of allowed roles and the list of denied roles as parameters
Reference: Role (authentication and authorization)

REST.Json.Types unit

JSONBooleanAttribute [JSONBoolean]
[XE6..10.3 Rio] See Data.DBXJSONReflect.JSONBooleanAttribute
JSONMarshalledAttribute [JSONMarshalled]
[XE6..10.3 Rio] See Data.DBXJSONReflect.JSONMarshalled
JSONOwnedAttribute [JSONOwned]
[XE6..10.3 Rio] See Data.DBXJSONReflect.JSONOwned
JSONNameAttribute [JSONName]
[XE6..10.3 Rio]

REST.JsonReflect unit

JsonReflect(XE5)/JsonReflectAttribute(XE6以降) [JsonReflect]
[XE5..10.3 Rio] Refer to Data.DBXJSONReflect.JsonReflect (class name changed in XE6)
JSONBooleanAttribute [JSONBoolean]
[XE5] Refer to Data.DBXJSONReflect.JSONBooleanAttribute (Move to REST.Json.Types unit after XE6)
JSONMarshalled [JSONMarshalled]
[XE5] Refer to Data.DBXJSONReflect.JSONMarshalled (Move to REST.Json.Types unit after XE6)
JSONOwned [JSONOwned]
[XE5] Refer to Data.DBXJSONReflect.JSONOwned (Move to REST.Json.Types unit after XE6)

EMS.ResourceType unit

TResourceCustomAttribute [TResourceCustom]
[10.1 Berlin..10.3 Rio] EndPointRequestSummaryAttribute (10.1 Berlin..10.2 Tokyo) / EndPointRequestParameterAttribute (10.1 Berlin..10.2 Tokyo) / EndPointResponseDetailsAttribute (10.1 Berlin..10.2 Tokyo) / EndPointObjectsYAMLDefinitionsAttribute (10.1 Berlin..10.2 Tokyo) / EndPointObjectsJSONDefinitionsAttribute ( 10.1 Berlin..10.3 Rio) / AllowAnonymousTenantAttribute (10.1 Berlin..10.2 Tokyo) / ResourceNameAttribute (10.3 Rio) / EndPointObjectsYAMLDefinitionsAttribute (10.3 Rio)
TEndpointCustomAttribute [TEndpointCustom]
[10.3 Rio] ResourceSuffixAttribute / EndpointNameAttribute / EndPointRequestSummaryAttribute / EndPointRequestParameterAttribute / EndPointResponseDetailsAttribute / AllowAnonymousTenantAttribute / EndPointProduceAttribute / EndPointMethodAttribute inheritance source
ResourceSuffixAttribute [ResourceSuffix]
[XE7..10.3 Rio] Specify URL suffix with EMS
Reference: Overview of EMS resources-RAD Studio
ResourceNameAttribute [ResourceName]
[XE7..10.3 Rio] Specify resource name in EMS
Reference: EMS Resource Overview-RAD Studio
EndpointNameAttribute [EndpointName]
[XE7..10.3 Rio] Specify endpoint method name in EMS
Reference: Overview of EMS resources-RAD Studio
EndPointRequestSummaryAttribute [EndPointRequestSummary]
[10.1 Berlin..10.3 Rio] Generate method description on API document with EMS
Reference: Custom API document-RAD Studio
EndPointRequestParameterAttribute [EndPointRequestParameter]
[10.1 Berlin..10.3 Rio] Generate description of parameters used in request in EMS on API document
Reference: Custom API document-RAD Studio
EndPointResponseDetailsAttribute [EndPointResponseDetails]
[10.1 Berlin..10.3 Rio] Generate request response description on API document with EMS
Reference: Custom API document-RAD Studio
EndPointObjectsYAMLDefinitionsAttribute [EndPointObjectsYAMLDefinitions]
[10.1 Berlin..10.3 Rio] Generate YAML version object definition on API document with EMS
Reference: Custom API document-RAD Studio
EndPointObjectsJSONDefinitionsAttribute [EndPointObjectsJSONDefinitions]
[10.1 Berlin..10.3 Rio] Generate JSON object definition on API document with EMS
Reference: Custom API document-RAD Studio
AllowAnonymousTenantAttribute [AllowAnonymousTenant]
[10.2 Tokyo..10.3 Rio] Skip the tenant verification procedure in EMS
Reference: Sample RAD server Multi-tenant application-RAD Studio
EndPointProduceAttribute
[10.3 Rio]
Reference: RAD Server extension URL mapping-RAD Studio
EndPointConsumeAttribute
[10.3 Rio]
Reference: RAD Server extension URL mapping-RAD Studio

Macapi.ObjectiveC unit

MethodNameAttribute [MethodName]
[XE4..10.3 Rio] Specify the original method name on Objective-C for Objective-C method defined in Delphi

Androidapi.JNIBridge unit

JavaSignatureAttribute [JavaSignature]
[XE5..10.3 Rio] Specify the original class name on Android for Android (JNI) class (interface) defined in Delphi

System.Win.WinRT unit

WinRTClassNameAttribute [WinRTClassName]
[10 Seattle..10.3 Rio] Specify the original class name on WinRT for the WinRT API interface defined in Delphi

Differences between Delphi versions:

In Delphi 2010 there are no predefined attributes to use in the system.
Delphi XE defined TRoleAuth for DataSnap and JSON … for JSON reflection for DBX.
Delphi XE2 defines ComponentPlatformsAttribute for multi-platform support.
Delphi XE3 defined WeakAttribute / UnsafeAttribute / RefAttribute for ARC, possibly TDefaultAttributeBase / DefaultAttribute / NoDefaultAttribute / StoredAttribute for the transition from the old RTTI to the new RTTI, and ObservableMemberAttribute for LiveBinding.
In Delphi XE4, MethodNameAttribute is defined for iOS.
In Delphi XE5, JSON reflection is separated from DBX, so Data.DBXJSONReflect’s JSON … is redefined in REST.JsonReflect, and JavaSignatureAttribute is defined for Android.
In Delphi XE6, the class name of REST.JsonReflect.JsonReflect has been changed to REST.JsonReflect.JsonReflectAttribute, and the definition of Json … other than JsonReflectAttribute has been moved from the REST.JsonReflect unit to the REST.Json.Types unit.
Delphi XE7 moved the StoredAttribute definition from the System.Classes unit to the System unit, and defined ResourceSuffixAttribute / ResourceNameAttribute / EndpointNameAttribute for EMS.
Delphi XE8 defined HPPGENAttribute and HFAAttribute.
In Delphi 10 Seattle, AlignAttribute and WinRTClassNameAttribute were defined.
Delphi 10.1 Berlin now supports the [weak] [unsafe] [volatile] attribute for all compilers (only NEXTGEN compiler before 10 Seattle). In addition , TResourceCustomAttribute / EndPointRequestSummaryAttribute / EndPointRequestParameterAttribute / EndPointResponseDetailsAttribute / EndPointObjectsYAMLDefinitionsAttribute / EndPointObjectsJSONDefinitionsAttribute for custom API document used for EMS API resource acquisition was defined.
In Delphi 10.2 Tokyo, the System.JSON.Serializers unit was added to define JSON serialization-related Json …, and AllowAnonymousTenantAttribute was defined to support EMS multi-tenancy. The System.JSON.Serializers unit is not officially documented at the moment (2017/04/10), so changes that are unlikely to be written in Lyna ‘s Delphi 10.2 Tokyo docwiki. – Zenryokuwawa , use of TJsonSerializer. – Zenryokuwawa , practical examples of TJsonSerializer – Zenryokuwawa See the per.
In Delphi 10.3 Rio, the inheritance relationship of attribute classes on the EMS.ResourceTypes unit has been rearranged.

If you want to specify an attribute for the return value of a method, such as the Unsafe attribute, [Result: <attr>]add a prefix before the method declaration ,

[Result: Unsafe]function Foo: TObject;

Like this.
2015/06/19 update: Added information about Delphi XE6 / XE7 / XE8.
2015/10/05 update: Added information about Delphi 10 Seattle.
2016/05/02 postscript: Added information about Delphi 10.1 Berlin.
2017/04/10 postscript: Added information about Delphi 10.2 Tokyo. I quoted a lot from Lyna . Thank you very much.
2019/03/07 update: Added information about Delphi 10.3 Rio.

Category: Delphi 10 Seattle , Delphi 10.1 Berlin , Delphi 10.2 Tokyo , Delphi 10.3 Rio , Delphi 2010 , Delphi Programming Tips , Delphi XE , Delphi XE2 , Delphi XE3 , Delphi XE4 , Delphi XE5 , Delphi XE6 , Delphi XE7 , Delphi XE8 At 15 : 25: 00

[WayBack] Compiler Attributes: Volatile – RAD Studio Berlin
[WayBack] Compiler Attributes: Volatile – RAD Studio XE8
[WayBack] Parameters (Delphi) – RAD Studio Rio (does not mention you can use attributes, bit you can)
[WayBack] Automatic Reference Counting in Delphi Mobile Compilers: UnsafeAttribute – RAD Studio Rio
[WayBack] Automatic Reference Counting in Delphi Mobile Compilers: WeakAttribute – RAD Studio Rio
[WayBack] What’s New: Attributes Supported by All Compilers – RAD Studio Berlin
Now, all Delphi compilers support the following attributes:

unsafe
volatile
weak

[WayBack] multithreading – Does Delphi have any equivalent to C’s volatile variable? – Stack Overflow

Q
In C and C++ a variable can be marked as volatile, which means the compiler will not optimize it because it may be modified external to the declaring object. Is there an equivalent in Delphi programming? If not a keyword, maybe a work around?
My thought was to use Absolute, but I wasn’t sure, and that may introduce other side effects.
A
According to The Delphi Language for Mobile Development whitepaper, Delphi’s mobile compilers have supported a [volatile] attribute since they were first introduced:
The volatile attribute is used to mark fields that are subject to change by different threads, so that code generation does not optimize copying the value in a register or another temporary memory location.
You can use the volatile attribute to mark the following declarations:

Variables (global and local)
Parameters
Fields of a record or a class.

You cannot use the volatile attribute to mark the following declarations:

Type
Procedures, Functions or Methods
Expressions

type
TMyClass = class
private
[volatile] FMyVariable: TMyType;
end;

Starting with Delphi 10.1 Berlin, the desktop compilers now support [volatile] as well.
Attributes Supported by All Compilers
Now, all Delphi compilers support the following attributes:

unsafe
volatile
weak

 

WhitePaler link above is behind a product registration wall despite the PDF also being available without registration at [WayBack] delphilanguagemobiledevelopmentwhitepaper170413.pdf via [WayBack] White Paper: The Delphi Language for Mobile Development and [WayBack] “The Delphi Language for Mobile Development” – Google Search.

System.VolatileAttribute

Delphi

VolatileAttribute = class(TCustomAttribute);

Properties

Type
Visibility
Source
Unit
Parent

class
public
System.pas
System
System

Description
TCustomAttribute is the base class for all Delphi attributes.
System.VolatileAttribute inherits from System.TCustomAttribute. All content below this line refers to System.TCustomAttribute.
TCustomAttribute is the base class for all Delphi attributes.
Declare descendants of TCustomAttribute to later use them as attributes in Delphi code. An attribute is a special kind of class that can be annotated to any type or member in Delphi.
See Also

System.Rtti.TRttiContext

Attributes
TObject Branch

Code Examples

AttributesAndRTTI Sample[WayBack] System.VolatileAttribute – RAD Studio API Documentation

Pointing to [WayBack] RTL.AttributesAndRTTI Sample – RAD Studio Code Examples

Pointing to a non-existing branch on the defunct open source repository: [WayBack] Page not found – SourceForge.net

Demos
Demos now are in either of these:

[WayBack] GitHub – Embarcadero/RADStudio10.3Demos: Delphi and C++Builder Demos for Embarcadero RAD Studio version 10.3 Rio
[WayBack] GitHub – Embarcadero/RADStudio10.3.2Demos: Delphi and C++Builder Demos for Embarcadero RAD Studio version 10.3.2 Rio

Unlike the past sourceforge version control archive, where you could track all the changes over Delphi versions (major, minor and work inbetween), now each major and minor version of Delphi gets a new repository with only a main branch.
This clearly shows Embarcadero has no clue on version control, and is oblivious of the majority of their sales being upgrades of customers interesting in changes over Delphi versions instead of only the last few commits for the current version.
–jeroen

Read More