delphi常量数组_如何在Delphi中声明和初始化常量数组
delphi 常量数组
In Delphi, the versatile web-programming language, allow a developer to refer to a series of variables by the same name and to use a number—an index—to tell them apart.
在通⽤的Web编程语⾔Delphi中, 允许开发⼈员使⽤相同的名称引⽤⼀系列变量,并使⽤数字(索引)来区分它们。
In most scenarios, you declare an array as a variable, which allows for array elements to be changed at run-time.
在⼤多数情况下,您将数组声明为变量,这允许在运⾏时更改数组元素。
However, sometimes you need to declare a constant array—a read-only array. You cannot change the value of a constant or a read-only variable. Therefore, while declaring a , you must also initialize it.
但是,有时您需要声明⼀个常量数组-⼀个只读数组。 您不能更改常量或只读变量的值。 因此,在声明 ,还必须对其进⾏初始化。
三个常量数组的⽰例声明 ( Example Declaration of Three Constant Arrays )
This code example declares and initializes three constant arrays, named Days, CursorMode, and Items.
此代码⽰例声明并初始化三个名为Days , CursorMode和Items的常量数组。
Days is a string array of six elements. Days[1] returns the Mon string.
天是由六个元素组成的字符串数组。 Days [1]返回Mon字符串。
CursorMode is an , whereby declaration CursorMode[false] = crHourGlass and CursorMode = crSQLWait. "cr*"
constants can be used to change the current screen cursor.
CursorMode是的 ,其中声明CursorMode [false] = crHourGlass和CursorMode = crSQLWait。 “ cr *”常量可⽤于更改当前屏幕光标。
Items defines an array of three TShopItem .
Items定义了三个TShopItem 的数组。
定义数组初始化type
TShopItem = record
Name : string;
Price : currency;
end;
const
Days : array[0..6] of string =
(
'Sun', 'Mon', 'Tue', 'Wed',
'Thu', 'Fri', 'Sat'
)
;
CursorMode : array[boolean] of TCursor =
(
crHourGlass, crSQLWait
) ;
Items : array[1..3] of TShopItem =
(
(Name : 'Clock'; Price : 20.99),
(Name : 'Pencil'; Price : 15.75),
(Name : 'Board'; Price : 42.96)
) ;
Trying to assign a value for an item in a constant array raises the "Left side cannot be assigned to" compile time error. For example, the following code does not successfully execute:
尝试为常量数组中的项⽬分配值会导致“⽆法分配左侧”的编译时间错误。 例如,以下代码⽆法成功执⾏:
Items[1].Name := 'Watch'; //will not compile
delphi 常量数组
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论