checklistbox1 中各项值均为Pass
checklistbox2 中各项值均为Fail两个checklistbox与一个listbox对应,添加记录已经没有问题,现在我想通过双击dbgrid中的记录,checklistbox中对应的值便打勾,代码如下:
with dbgrid1 do begin
  for i:=0 to listbox1.Items.Count-1 do begin
    if checklistbox1.Items.Strings[i]=fields[i].AsString then
      checklistbox1.Checked[i]:=true
    else if checklistbox2.Items.Strings[i]=Fields[i].AsString then
      checklistbox2.Checked[i]:=true
    else
    checklistbox1.Checked[i]:=false;
    checklistbox2.Checked[i]:=false;
    end;代码有什么问题?为什么双击记录没反应呢?

解决方案 »

  1.   

    with dbgrid1 do 
    begin
      for i:=0 to listbox1.Items.Count-1 do 
      begin
        checklistbox1.Checked[i] := checklistbox1.Items.Strings[i]=fields[i].AsString;
        checklistbox2.Checked[i] := checklistbox2.Items.Strings[i]=Fields[i].AsString;
      end;
    end; 
      

  2.   

    编译的时候有如下提示:
    FOR-LOOP variable 'i' may be undefined after loop
    是什么意思?
    程序可以运行,但是双击记录时,checklistbox里面还是没打勾