procedure TForm1.Button1Click(Sender: TObject);
var
  i,k:integer;
begin
  for i:=0 to 9 do
    begin
      listbox1.items.add(inttostr(i));
      if listbox1.items[i]=inttostr(4) then
            k:=i;
    end;
  Label1.caption:=intToStr(k);
end;procedure TForm1.Button1Click(Sender: TObject);
var
  i,k:integer;
begin
  for i:=0 to 9 do
    begin
      listbox1.items.add(inttostr(i));
      if listbox1.items[i]='4' then
            k:=i;
    end;
  Label1.caption:=intToStr(k);
end;我的两个测试代码都是4!!!!

解决方案 »

  1.   

    没有什么学问、问题的。sundayboys(sunboy) 是对的。
      

  2.   

    将 if listbox1.item[i]=inttostr(4) then 
    换成:
    if listbox1.item[i]=trim(inttostr(4)) then 
      

  3.   

    var 
      i,k:integer;
    begin    
      for i:=0 to 9 do
        begin
          listbox1.items.add(itntostr(i));                <-----itntostr 错误
          if listbox1.item[i]=inttostr(4) then            <-----item     错误
                k:=i;
        end;答案是4
      

  4.   

    哈哈,看来果然是没睡醒啊。但是他的“itntostr(4)”为什么编译通过了呢
      

  5.   

    To eeverybody      
        不好意思
        我浪费大家的时间了!
         谢谢大家!