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

From Lazarus wiki
Jump to navigationJump to search
(Created page with "{{Enumerated types}} 5A - データ型 (著者: Tao Yue, 状態: 原文のまま変更なし) You can declare your own ordinal data types. You do this in the type section of...")
 
Line 3: Line 3:
 
5A - データ型 (著者: Tao Yue, 状態: 原文のまま変更なし)
 
5A - データ型 (著者: Tao Yue, 状態: 原文のまま変更なし)
  
You can declare your own ordinal data types. You do this in the type section of your program:
+
自分のオリジナルなデータ型を宣言することができる。これはプログラムの型セクション(type section)で行う。
 
<syntaxhighlight>
 
<syntaxhighlight>
 
type
 
type
Line 9: Line 9:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
One way to do it is by creating an enumerated type. An enumerated type specification has the syntax:
+
ひとつの方法は列挙型(enumerated type)を作ることである。列挙型の指定は次のようにする。
 
  (identifier1, identifier2, ... identifiern)
 
  (identifier1, identifier2, ... identifiern)
  
For example, if you wanted to declare the months of the year, you would do a type:
+
例えば、月を宣言したいなら、次のようになる。
 
<syntaxhighlight>
 
<syntaxhighlight>
 
type
 
type
Line 20: Line 20:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
You can then declare a variable:
+
そうすれば、変数を宣言できるようになる。
 
<syntaxhighlight>
 
<syntaxhighlight>
 
var
 
var
Line 26: Line 26:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
You can assign any enumerated value to the variable:
+
変数に列挙値を割り当てることができる。
 
<syntaxhighlight>
 
<syntaxhighlight>
 
Month := January;
 
Month := January;
 
</syntaxhighlight>
 
</syntaxhighlight>
  
All the ordinal functions are valid on the enumerated type. <tt>ord(January) = 0</tt>, and <tt>ord(December) = 11</tt>.
+
列挙型にはすべての順序関数が適用できる。<tt>ord(January) = 0</tt> <tt>ord(December) = 11</tt>である。
  
A few restrictions apply, though: enumerated types are internal to a program -- they can neither be read from nor written to a text file. You must read data in and convert it to an enumerated type. Also, the identifier used in the type (such as <tt>January</tt>) cannot be used in another type.
+
しかし、制限もある。列挙型はプログラムに内在的でテキストファイルから読み込んだり、書き出したりすることはできない。データを読み込み、列挙型に変換しなくてはならない。また、この型で用いられた識別子(例えば、<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.
 
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.

Revision as of 04:21, 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)は別な型では使用できない。

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.

previous contents next