2017년 2월 14일 화요일
[Delphi] How to Declare and Initialize Constant Arrays in Delphi
In Delphi, arrays 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.
In most scenarios, you declare an array as a variable -- thus allowing for array elements to be changed at run-time.
Sometimes, however, 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 constant array you must also initialize it.
Example
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) ) ;
This code declares and initializes three constant arrays, named: "Days," "CursorMode" and "Items."
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기