function TForm1.MonthDays(iYear,iMonth:Word):Word;
begin
case iMonth of
1,3,5,7,8,10,12: Result:=31;
4,6,9,11: Result:=30;
2://如果是闰年
if IsLeapYear(iYear) then Result:=29
else Result:=28
else
Result:=0;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j,k,L : integer;
tNode : TTreeNode;
tYNode,tMNode : TTreeNode;
begin
tNode := tvYear.Items.Add(nil,'日期列表');
for I:= 2002 to 2050 do
begin
tYNode := tvYear.Items.AddChild(tNode,IntToStr(I)+'年');
for J := 1 to 12 do
begin
if J < 10 then
tMNode := tvYear.Items.AddChild(tYNode,'0'+IntToStr(J)+'月')
else
tMNode := tvYear.Items.AddChild(tYNode,IntToStr(J)+'月');
L := MonthDays(i,j);
for K := 1 to L do
if K < 10 then
tvYear.Items.AddChild(tMNode,'0'+IntToStr(K)+'日')
else
tvYear.Items.AddChild(tMNode,IntToStr(K)+'日');
end;
end;
end;