Joh*_*ica 16 delphi documentation intrinsics
Delphi有这个列表:Delphi内在例程
但该列表不完整.
哪些无证的内在函数存在,因为它们的目的何时和目的是什么?
Joh*_*ica 25
我知道以下无证的内在函数.
Delphi 2007:这里和Hallvard的博客:
默认
function Default(T: Typeidentifier): value of T;
Run Code Online (Sandbox Code Playgroud)
返回类型标识符的零表示T.
在XE7 beta博客和Stefan Glienke中解释了XE7中引入的以下内在函数
IsManagedType
function IsManagedType(T: TypeIdentifier): Boolean;
Run Code Online (Sandbox Code Playgroud)
如果T是interface,string或dynamic array,或包含此类的记录,则为真.包含托管类型的类将返回false.
在XE6及更早版本中,您必须使用System.Rtti.IsManaged(TypeInfo(T)).
HasWeakRef
function HasWeakRef(T: TypeIdentifier): Boolean;
Run Code Online (Sandbox Code Playgroud)
如果T已注释为真,则为真[weak].编译器保留[weak]引用列表.您不能使用move这些类型和其他技巧,因为这将阻止弱列表更新.
在XE6及更早版本中,您必须使用System.TypInfo.HasWeakRef(TypeInfo(T)).
GetTypeKind
function GetTypeKind(T: TypeIdentifier): TTypeKind;
Run Code Online (Sandbox Code Playgroud)
同样的事情是PTypeInfo(System.TypeInfo(T))^.Kind;,因为它是编译器内在函数,在编译时解析函数,并且编译器将剥离计算结果为false的条件代码.
IsConstValue
function IsConstValue(const Value): Boolean;
Run Code Online (Sandbox Code Playgroud)
如果Value是常量,则为True,否则为false.
这有助于编译器消除死代码,因为在编译时会对函数进行求值.
这仅适用于内联函数,它允许更短的生成代码.
所属类别
function TypeInfo(T: typeindentifier): PTypeInfo;
Run Code Online (Sandbox Code Playgroud)
这个功能是不是无证这样,但什么是无证的,这是因为XE7的内在功能.
这意味着if TypeInfo(T) = TypeInfo(byte) then ...如果T不是一个字节,则代码片段不会生成任何代码,并且测试将在编译时解析.
但是,编译时解决方案仅适用于通用例程,并且仅在进行if (TypeInfo(T) = TypeInfo(sometype)测试时才有效.即使
测试if TypeInfo(byte) = TypeInfo(smallint) then总是为假,测试也不会被消除.
也没有其他用途TypeInfo(T).
退货地址
以下内容与raise exception at returnaddress构造一起使用.
function ReturnAddress(Expression): pointer; //Delphi ?
function AddressOfReturnAddress(Expression): pointer; //Delphi ?
Run Code Online (Sandbox Code Playgroud)
据我所知,你无法直接从用户代码中调用它们.
例子 IsConstValue
type TFlavor = (Tasty, Nasty); TIntegerHelper = record helper for integer function GetSomething(Flavor: TFlavor): TPoint; inline; private function GetTastyPoint: TPoint; function GetNastyPoint: TPoint; end; function TIntegerHelper.GetSomething(Flavor: TFlavor): TPoint; begin if IsConstValue(Flavor) then begin if Flavor = Tasty then Result:= Self.GetTastyPoint else Result:= Self.GetNastyPoint; end else begin Assert(1=0, 'This function can only be called with constant parameters'); end; end; procedure Test; var pt: TPoint; begin pt:= 100000.GetSomething(Tasty);此调用将转换为GetTastyPoint,if/then链接将消除序列.