Delphi高级数据类型:枚举类型



type
  Week = (Sun, Mon, Tue, Wed, Thu, Fri, Sat);

{$R *.dfm}

function mday(day: Week):string;
begin
  case day of
    Sun: mday := '星期天';
    MOn: mday := '星期一';
    Tue: mday := '星期二';
    Wed: mday := '星期三';
    Thu: mday := '星期四';
    Fri: mday := '星期五';
    Sat: mday := '星期六';
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  year, month, day: word;
begin
  DecodeDate(date, year, month, day);
  edit1.Text := format('%d年%d月%d日', [year, month ,day]);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  yesterday, today, tomorrow: Week;
  n: integer;
begin
  n := dayofweek(now);
  case n of
    1: today := Sun;
    2: today := Mon;
    3: today := Tue;
    4: today := Wed;
    5: today := Thu;
    6: today := Fri;
    7: today := Sat;
  end;

  if today = Low(Week) then
    yesterday := high(week)
  else
    yesterday := Pred(today);

  if today = high(week) then
    tomorrow := low(week)
  else
    tomorrow := succ(today);

  Button1.Caption := '昨天';
  Button2.Caption := '今天';
  Button3.Caption := '明天';

  case (sender as TButton).Tag of
    0: Button1.Caption := '昨天是' + mday(yesterday);
    1: Button2.Caption := '今天是' + mday(today);
    2: Button3.Caption := '明天是' + mday(tomorrow);
  end;
end;


[本日志由 admin 于 2014-01-03 07:45 PM 更新]
上一篇: 一个ASP版的AES加密类
下一篇: Delphi高级数据类型:子界类型
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: Delphi 数据类型 枚举类型
相关日志:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭