Difference between revisions of "Basic Pascal Tutorial/Chapter 5/Enumerated types/ja"

From Lazarus wiki
Jump to navigationJump to search
Line 35: Line 35:
 
しかし、制限もある。列挙型はプログラムに内在的でテキストファイルから読み込んだり、書き出したりすることはできない。データを読み込み、列挙型に変換しなくてはならない。また、この型で用いられた識別子(例えば、<tt>January</tt>)は別な型では使用できない。
 
しかし、制限もある。列挙型はプログラムに内在的でテキストファイルから読み込んだり、書き出したりすることはできない。データを読み込み、列挙型に変換しなくてはならない。また、この型で用いられた識別子(例えば、<tt>January</tt>)は別な型では使用できない。
  
One purpose of an enumerated type is to allow you, the programmer, to refer to meaningful names for data. In addition, enumerated types allow functions and procedures to be assured of a valid parameter, since only variables of the enumerated type can be passed in and the variable can only have one of the several enumerated values.
+
列挙型の目的のひとつはプログラマーがデータに対して意味のある名前を与えることを可能にすることである。加えて、列挙型は関数や手続きが妥当なパラメータであることを保証してくれる。なぜなら、列挙型の変数だけが許され、列挙値の一つだけを持っているからである。
  
 
{|style=color-backgroud="white" cellspacing="20"
 
{|style=color-backgroud="white" cellspacing="20"

Revision as of 04:29, 19 September 2015

български (bg) English (en) français (fr) 日本語 (ja) 中文(中国大陆)‎ (zh_CN)

5A - データ型 (著者: Tao Yue, 状態: 原文のまま変更なし)

自分のオリジナルなデータ型を宣言することができる。これはプログラムの型セクション(type section)で行う。

type
 datatypeidentifier = typespecification;

ひとつの方法は列挙型(enumerated type)を作ることである。列挙型の指定は次のようにする。

(identifier1, identifier2, ... identifiern)

例えば、月を宣言したいなら、次のようになる。

type
  MonthType = (January, February, March, April,
              May, June, July, August, September,
              October, November, December);

そうすれば、変数を宣言できるようになる。

var
  Month : MonthType;

変数に列挙値を割り当てることができる。

Month := January;

列挙型にはすべての順序関数が適用できる。ord(January) = 0ord(December) = 11である。

しかし、制限もある。列挙型はプログラムに内在的でテキストファイルから読み込んだり、書き出したりすることはできない。データを読み込み、列挙型に変換しなくてはならない。また、この型で用いられた識別子(例えば、January)は別な型では使用できない。

列挙型の目的のひとつはプログラマーがデータに対して意味のある名前を与えることを可能にすることである。加えて、列挙型は関数や手続きが妥当なパラメータであることを保証してくれる。なぜなら、列挙型の変数だけが許され、列挙値の一つだけを持っているからである。

previous contents next