//目前是1月 ,要查去年12月的

  if MonthOf(Date) = 1 then //目前是1月 ,要查去年12月的
    Y := -1 //要显示去年
  else
    Y := 0;
  for I := 12 downto 1 do
    cmbMonth.Items.Add(Format('%d-%.2d', [YearOf(Date) + Y, I]));

  if Y = 0 then
    cmbMonth.ItemIndex := cmbMonth.Items.IndexOf(Format('%d-%.2d', [YearOf(Date), MonthOf(Date)- 1])) //目前是 2-12月,查本年 1- 11月的
  else
    cmbMonth.ItemIndex := cmbMonth.Items.IndexOf(Format('%d-%.2d', [YearOf(Date) -1, 12]));//目前是1月,查去年12月

猜你喜欢

转载自www.cnblogs.com/CodeGear/p/11861077.html