comboBOX中怎样自动建立年月查询?显示当前年和当前月份,并显示过去三个月!
如目前为2006年1月份在combobox中显示:
2006-01
2005-12
2005-11
2005-10

解决方案 »

  1.   

    procedure autoLoadDate(aDate: TDate; Months: integer);
    var
      y,m,d: word;
      i: integer;
    begin
     comboBox1.Items.Clear;
     for i:=1 to Months do begin
       DecodeDate(incMonth(aDate,i), y, m, d);
       ComboBox1.Items.Add(inttostr(y)+'-'+inttostr(m));   
     end;
    end;
      

  2.   

    楼上的好象没有把条件判断完
    我是这样写的完全可以:
    procedure Tform1.FormCreate(Sender: TObject);
    var  y,m,d,y2,m2,d2,y3,m3,d3: word;
         i: integer;
         mindate:Tdatetime;
         nextdate:Tdatetime;
    begin
          comboBox1.Items.Clear;
          decodedate(date,y,m,d);
          mindate:=incMonth(date,-3);  //减3个月取得10月
          decodedate(mindate,y2,m2,d2);
          i:=-1;
          ComboBox1.Items.Add(inttostr(y)+'-'+inttostr(m));
          while m3<>m2 do
          begin
            nextdate:=incMonth(date,i);
            decodedate(nextdate,y3,m3,d3);
            ComboBox1.Items.Add(inttostr(y3)+'-'+inttostr(m3));
            next;
            i:=i+(-1);
          end;
    end;