Enum 列挙型
VBの Enum は列挙型を宣言します。
Delphi では type で宣言します。ただし、VBのように値を設定することはできません。
列挙型などの型名の先頭には T を付けるのが一般的です。
| ■ 列挙型の使用例 |
type
TMonth = (mtJan, mtFeb, mtMar, mtApr, mtMay, mtJun,
mtJul, mtAug, mtSep, mtOct, mtNov, mtDec);
・
・
(中略)
・
・
procedure TForm1.Button1Click(Sender: TObject);
var
D : TMonth;
begin
for D := mtFeb to mtApr do begin
ShowMessage(IntToStr(GetMonth(D)));
end;
end;
function TForm1.GetMonth(Month: TMonth) : integer;
begin
case Month of
mtJan : Result := 1;
mtFeb : Result := 2;
mtMar : Result := 3;
mtApr : Result := 4;
mtMay : Result := 5;
mtJun : Result := 6;
mtJul : Result := 7;
mtAug : Result := 8;
mtSep : Result := 9;
mtOct : Result := 10;
mtNov : Result := 11;
mtDec : Result := 12;
end;
end;
|