Delphi compiler properties (particularly modifier Ref, Unsafe, Volatile, Weak)

Ref 1
Delphi in constant parameters like a local constant or read-only variables. Constant parameters and parameter values similar except not give constant parameter assignment procedure or function in vivo, and can not be passed to the other parameters constant var type parameter. (However, if you pass a constant argument it is an object reference, you can still modify the properties of the object)

Use const enables the compiler to optimize code structure and parameters of type string. And it also provides a protection against inadvertently passed a reference to the other process parameters.

Constant Parameters may be passed by value or by reference to the function mode, depending on the compiler used. If you want to force the compiler to use constant parameters passed by reference, you can use the [Ref] modifier with the const keyword. The modifier which can in front const, may be behind const.

E.g:

FunctionName function (const [Ref] parameter1: Record1Name; [Ref] const parameter2: Class2Name);
2 the Unsafe
used to mark the return value so that the compiler automatically Result reference count (ARC) to disable it.

[Result: Unsafe] function ReturnUnsafe: TObject;
except System unit, in very rare cases can also be used to modify a member variable or parameter. However, such use is not recommended, because it did not produce the relevant code reference count is dangerous.

3 Volatile
used to mark variables, parameters, field members may be modified by another thread, so that it does not produce a copy of the temporary register or a memory location optimization.

type
TMyClass class =
Private
[volatile] FMyVariable: TMyType;
End;
. 4 Weak
statement weak.

of the type
TComponent = class (TPersistent, IInterface,
IInterfaceComponentReference)
Private
[Weak] FOwner: TComponent;
---------------------
Author: tht2009
Source: CSDN
Original: https: //blog.csdn.net/tht2009/article/details/50465324
Disclaimer: This article is a blogger original article, reproduced, please attach Bowen link!

 

Guess you like

Origin www.cnblogs.com/findumars/p/11128250.html