[定数]
◆定数の宣言
constキーワードで定数を宣言します。
書式は「const 定数名 =値;」,「const 定数名:型 =値;」となります。
定数を宣言している例です。
const MaxValue = 255;
const MaxV = Int64(256);
const Achar = Byte($41);
const Pi:Extended = 3.1415926535898;
const MaxLength:Integer = 255;
const str = '文字列リテラル';
const WeekName : array [0..6] of string = ('日','月','火','水','木','金','土');
const Number : array [0..9] of Char = ('0','1','2','3','4','5','6','7','8','9');
const Number : array [0..9] of Char = '0123456789';
const
bytesize: Integer = SizeOf(Byte);
a: Integer = Ord('a');
x: Integer = Round(128.5678);
◆リテラル
定数に対して、明示的にその型を示したい時期があります。
そのような場合は、リテラルを用います。
型 | 例 |
Shortint | Shortint(123) |
Smallint | Smallint(123) |
Longint | Longint(123) |
Int64 | Int64(123) |
Byte | Byte(123) |
Word | word(123) |
Longword | Longword(123) |
Char | 'a' |
string | 'abcd' |
TDateTime | StrToDateTime('2009/06/29') |
Copyright c 2009, ohishi,All rights reserved.