问题描述
在mORMot的SynCommons.pas中有以下代码片段:
In mORMot's SynCommons.pas there is the following snippet of code:
type
....
TTimeLog = type Int64;
^^^^
第二个的目的是什么类型
关键字(在 Int64
前面)?
What is the purpose of the second type
keyword (in front of Int64
)?
推荐答案
来自
type TValue = Real;
var
X: Real;
Y: TValue;
X和Y属于同一类型;在运行时,
无法将TValue与Real区分开。
通常没有什么意义,但是如果您定义新类型的目的是利用运行时类型
信息,例如,将属性编辑器与特定类型的
属性相关联- 不同的
名称和不同类型之间的区别变得很重要。在这种情况下,请使用
语法:
X and Y are of the same type; at runtime, there is no way to distinguish TValue from Real. This is usually of little consequence, but if your purpose in defining a new type is to utilize runtime type information, for example, to associate a property editor with properties of a particular type - the distinction between 'different name' and 'different type' becomes important. In this case, use the syntax:
type newTypeName = type KnownType
例如:
type TValue = type Real;
强制编译器创建一个新的独特类型,称为TValue。
forces the compiler to create a new, distinct type called TValue.
对于var参数,形式和实际类型必须相同。以
为例:
For var parameters, types of formal and actual must be identical. For example:
type
TMyType = type Integer;
procedure p(var t:TMyType);
begin
end;
procedure x;
var
m: TMyType;
i: Integer;
begin
p(m); // Works
p(i); // Error! Types of formal and actual must be identical.
end;
这篇关于在类型声明中在=之后键入什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!