FOR循环语句

来源:百度知道 编辑:UC知道 时间:2024/05/19 04:14:13
procedure Tstu_cj_form.FormCreate(Sender: TObject);
var i,s:integer;
begin
with mainmodel.topic_query do
begin
close; //next
sql.Clear;
sql.Add('select topic_name from topic_types');
open;
if mainmodel.topic_query.RecordCount<>0 then
begin
s:=mainmodel.topic_query.RecordCount;
for i:=1 to s do
combobox1.Items.Text:=mainmodel.topic_query.fieldbyname('topic_name').Value;
i:=i+1;
next;
if i>s then
exit;
end;
end;
end;

如上代码.我想把我数据表里的所有相关字段即'topic_name'传给我的一个 叫COMBOBOX的控件.现在要写FOR语句,应该怎么写.我不会.谢谢.
我用DELPHI

for i:=1 to s do
combobox1.Items.Text:=mainmodel.topic_query.fieldbyname('topic_name').Value;
i:=i+1;

这里不就已经实现了吗,只不过格式有点不正确,更正一下:

for i:=1 to s do
combobox1.add(mainmodel.topic_query.fieldbyname('topic_name').Value);