我也是新手,看到题目手痒,这是我写的代码,已通过!请大家指教!
procedure TForm1.Button2Click(Sender: TObject);
var
year1: string;
year2: integer;
month1: string;
month2: integer;
mont: integer;
days2: integer;
days4: integer;
days1: string;
days3: integer;
i: integer;
mont1,mont2,mont3 : set of 01..12;
begin
mont1:=[01,03,05,07,08,10,12];
mont2:=[04,06,09,11];
mont3:=[02];
days2:=0;
year1:=LeftStr(edit2.Text,4);
month1:=MidStr(edit2.Text,6,2);
days1:=RightStr(edit2.Text,2);
year2:= StrToInt(year1);
month2:=StrToInt(month1);
days3:= StrToInt(days1);
mont:=month2;
for i:= 1 to mont-1 do
begin
if i in mont1 then
days4:=31
else
if
i in mont2
then
days4:=30
else
if
i in mont3
then
if IsLeapYear(year2)=true then
days4:=29
else
days4:=28;
days2:=days2+days4;
end;
days2:=days2+days3;
edit3.Text:=edit2.Text;
edit4.Text:=IntToStr(days2);
end;