//这个过程的目的,只是想把listbox1中的各项,赋值给数组b
procedure Set_Order();      
type b1=array of integer;
var
  n,i:integer;  
  b:b1;begin
  n:=form1.ListBox1.Items.Count;
  
  for i:=1 to n do
  begin
    showmessage(inttostr(i));
    showmessage(form1.ListBox1.Items[i-1]);
    b[i]:=strtoint(trim(form1.ListBox1.Items[i-1]));/*就是这句出错了,而且编译时没错,运行时,我在listbox1中加入数字时,然后再让他赋值时,就出现了'Project xxxx raised exception class yyyyy with message 'zzzzzz'.Process stopped.  Use Step or Run to continue.'提示,然后程序中止运行,但我肯定,listbox中输入的只是100以内的数字*/
  end;end;

解决方案 »

  1.   

    我猜想会不会是listbox1.items[i]中的内容除了数字,还包含别的字符造成的呢?但我已经加上了trim()来去掉多余字符了.
    真的不明白
      

  2.   

    procedure Set_Order();      
    type b1=array of integer;
    var
      n,i:integer;  
      b:b1;begin
      n:=form1.ListBox1.Items.Count;  setLength(b,n);//加上这句,为动态数组设置长度  for i:=0 to n-1 do
      begin
        showmessage(inttostr(i));
        showmessage(form1.ListBox1.Items[i]);
        b[i]:=strtoint(trim(form1.ListBox1.Items[i]));
      end;
    end;
      

  3.   

    b[i]:=strtointdef(trim(form1.ListBox1.Items[i-1]),0);