Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does type after the = do in a type declaration

Tags:

delphi

In mORMot's SynCommons.pas there is the following snippet of code:

type
  ....
  TTimeLog = type Int64;
             ^^^^

What is the purpose of the second type keyword (in front of Int64)?

like image 551
Johan Avatar asked Jun 12 '14 13:06

Johan


People also ask

What is a type declaration?

A type declaration statement specifies the type, length, and attributes of objects and functions. You can assign initial values to objects. A declaration type specification (declaration_type_spec) is used in a nonexecutable statement.

What is ?: In TypeScript?

Using ?: with undefined as type definition While there are no errors with this interface definition, it is inferred the property value could undefined without explicitly defining the property type as undefined . In case the middleName property doesn't get a value, by default, its value will be undefined .

What is the type of a file in TypeScript?

TypeScript has two main kinds of files. . ts files are implementation files that contain types and executable code. These are the files that produce . js outputs, and are where you'd normally write your code.

What is type of function in TypeScript?

Introduction to TypeScript function typesThe function type accepts two arguments: x and y with the type number . The type of the return value is number that follows the fat arrow ( => ) appeared between parameters and return type.


1 Answers

From Data Types, Variables, and Constants Index (Delphi)

When you declare a type that is identical to an existing type, the compiler treats the new type identifier as an alias for the old one. Thus, given the declarations:

type TValue = Real;
var
  X: Real;
  Y: TValue;

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

For example:

type TValue = type Real;

forces the compiler to create a new, distinct type called TValue.

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;
like image 190
Rafael Colucci Avatar answered Oct 02 '22 19:10

Rafael Colucci