Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə113/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   109   110   111   112   113   114   115   116   ...   294
DelphiLanguageGuide

Declaring Types
This topic describes the syntax of Delphi type declarations.
Type Declaration Syntax
A type declaration specifies an identifier that denotes a type. The syntax for a type declaration is
type newTypeName 
 = 
 type
where newTypeName is a valid identifier. For example, given the type declaration
type TMyString = string;
you can make the variable declaration
var S: TMyString;
A type identifier's scope doesn't include the type declaration itself (except for pointer types). So you cannot, for
example, define a record type that uses itself recursively.
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 informationfor 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 
 = 
typetype
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
100


  p(m); // Works
  p(i); // Error! Types of formal and actual must be identical.
end;
Note:
This only applies to 
var
 parameters, not to 
const
 or by-value parameters.
101


Variables
A variable is an identifier whose value can change at runtime. Put differently, a variable is a name for a location in
memory; you can use the name to read or write to the memory location. Variables are like containers for data, and,
because they are typed, they tell the compiler how to interpret the data they hold.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   109   110   111   112   113   114   115   116   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin