设想打开一个以年为文件名的数据库文件,ComboBox1里写好1—12的items,根据不同月份的改变在ComboBox2里面列出当月日子,我用了for循环,但始终不对,能指点一下吗?
var
i:integer;
j:string;
begin
if ComboBox1.ItemIndex = 0 then
begin
for i:= 1 to 31 do
begin
j := IntToStr(i);
ComboBox2.Items.Text := j;
end;
end;
各位谢谢了
var
i:integer;
j:string;
begin
if ComboBox1.ItemIndex = 0 then
begin
for i:= 1 to 31 do
begin
j := IntToStr(i);
ComboBox2.Items.Text := j;
end;
end;
各位谢谢了
你想用这句来实现什么功能?
for i:= 1 to 31 do
begin
j := IntToStr(i);
ComboBox2.Items.Text := j;
end;
这个循环的前三十次算是白执行了
var
date,date2 :string;
date3,date4 :Tdatetime;
begin
date :=combobox1.text+'-'+combobox2.text+'-1';
date2 :=combobox1.text+'-'+intostr(strtoint(combobox2.text)+1)+'-1'; date3:=strtodate(date);
date4:=strtodate(date2)-1;
combobox3.clear;
while date3<=date4 do
begin
combobox3.items.add(Formatdatetime('dd',date3));
date3 :=date3+1;
end;
end;
begin
j := IntToStr(i);
ComboBox2.Items.Text := j;
end;
我就是不知道为什么这三十次白执行了啊,为什么不能在ComboBox2里显出来呢
begin
j := IntToStr(i);
ComboBox2.Items.Text := j;
end;前30次循环执行了,但是你看不到结果,因为只有最后那个31会被显示出来。
按钮中的代码是:procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
j: string;
begin
for i:= 1 to 31 do
begin
j := IntToStr(i);
ComboBox1.Items.Add(j);
combobox1.Text:=combobox1.Items[i-1];
end;
end;这样执行,按一下按钮,你就会发现实际上每个循环都执行了,数据也是写对的。
只不过前30次循环的结果“太快了”,你看不到它显示出来。
var
i,j:integer;
begin
if ComboBox1.ItemIndex<>-1 Then
Begin
ComboBox1.Clear;
case ComboBox1.IntemIndex of
0,2,4,6,7,9,11:i:=31
3,5,8,10:i:=30;
1:
begin
if IsLeapYear(StrToInt(FormatDateTime('YYYY',Date)) Then
i:=29 else i:=28;
end;
End;
for j:=1 to i do
ComBoBox2.Item.add(intToStr(j));
ComBoBox2.ItemIndex:=0;
End;
end;