delphi 數(shù)組與枚舉
來源:教育資源網(wǎng)
?
發(fā)布時間:2021-05-13 14:57:17
?
點擊:32
數(shù)組與枚舉
type
TMyEnum = (Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday); {定義枚舉}
var
weekArr: array[TMyEnum] of string; {定義數(shù)組}
myEnum: TMyEnum; {定義枚舉變量}
begin
{數(shù)組賦值}
weekArr[Monday] := '星期一';
weekArr[Tuesday] := '星期二';
weekArr[Wednesday] := '星期三';
weekArr[Thursday] := '星期四';
weekArr[Friday] := '星期五';
weekArr[Saturday] := '星期六';
weekArr[Sunday] := '星期天';
{調(diào)用數(shù)組}
ShowMessage(weekArr[Sunday]); {星期天}
{遍歷數(shù)組}
for myEnum := Low(weekArr) to High(weekArr) do
begin
ShowMessage(weekArr[myEnum]); {將分別顯示: 星期一 ... 星期天}
end;
end;
type
TMyEnum = (Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday); {定義枚舉}
var
weekArr: array[TMyEnum] of string; {定義數(shù)組}
myEnum: TMyEnum; {定義枚舉變量}
begin
{數(shù)組賦值}
weekArr[Monday] := '星期一';
weekArr[Tuesday] := '星期二';
weekArr[Wednesday] := '星期三';
weekArr[Thursday] := '星期四';
weekArr[Friday] := '星期五';
weekArr[Saturday] := '星期六';
weekArr[Sunday] := '星期天';
{調(diào)用數(shù)組}
ShowMessage(weekArr[Sunday]); {星期天}
{遍歷數(shù)組}
for myEnum := Low(weekArr) to High(weekArr) do
begin
ShowMessage(weekArr[myEnum]); {將分別顯示: 星期一 ... 星期天}
end;
end;