花了两个多小时写的程序~~调试没问题~~可运行出了问题~~~~
说什么project raised exception class Einvalidpointer with message "invalid pointer operation".process stopped
  问题大致出在哪啊
 我是在列表框1输出100个二位数,然后在列表框2里显示素数并排序~~
 但是我输出1000个的话,却能成功运行啊~~~
很汗啊 ~~帮帮忙吧....小女子感激不尽....

解决方案 »

  1.   

    unit shiyan2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Label1: TLabel;
        Label2: TLabel;
        Button1: TButton;
        ListBox1: TListBox;
        GroupBox1: TGroupBox;
        RadioButton1: TRadioButton;
        RadioButton2: TRadioButton;
        Button2: TButton;
        ListBox2: TListBox;
        CheckBox1: TCheckBox;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var n,i:integer;
    begin
     if radiobutton1.Checked=true then
       ListBox1.Items.Add(Edit1.Text);
       edit1.Text:='';
    if radiobutton2.Checked=true then
       begin
        ListBox1.Items.Clear;
        n:=strtoint(edit2.Text);
        for i:=1 to n do
          ListBox1.Items.Add(inttostr(round(random(100))+1));
        edit2.Text:='';
       end;
    end;
    procedure TForm1.Button2Click(Sender: TObject);
    var n,i,j,temp,index:integer;
    var a:array of integer;
    begin
       listbox2.Clear;
       n:=0;
       index:=0;
       while n<=listbox1.Count-1 do
         begin
           if strtoint(listbox1.Items[n])<=2 then
             begin
              if  strtoint(listbox1.Items[n])=2 then
                  begin
                   listbox2.Items.Add(listbox1.Items[n]);
                   index:=index+1;
                  end;
              if  strtoint(listbox1.Items[n])<>2 then
                   n:=n+1;
             end;
           if strtoint(listbox1.Items[n])>2 then
            begin
              for i:=2 to strtoint(listbox1.Items[n])-1 do
                if strtoint(listbox1.Items[n]) mod i=0 then
                  break;
                if i>strtoint(listbox1.Items[n])-1 then
                 begin
                  listbox2.Items.Add(listbox1.Items[n]);
                  index:=index+1;
                 end;
            end;
                  n:=n+1;
         end;
              if checkbox1.Checked=true then
           begin
            setlength(a,index-1);
            for i:=0 to index-1 do
              a[i]:=strtoint(listbox2.Items[i]);
            for i:=0 to index-2 do
               for j:=i+1 to index-1 do
                   if a[i]>a[j] then
                    begin
                      temp:=a[i];
                      a[i]:=a[j];
                      a[j]:=temp;
                    end;
            listbox2.Clear;
            for i:=0 to index-1 do
               listbox2.Items.Add(inttostr(a[i]));
           end;
       setlength(a,0);end;
    end.
    这是代码...多谢了啊~~~
      

  2.   

    setlength(a,index-1);
            for i:=0 to index-1 do //改为for i:=0 to index-2试试
              a[i]:=strtoint(listbox2.Items[i]);
      

  3.   

    不行啊~~还是一样~~
    弱弱的说一句:index-1 没越界吧~~
      

  4.   

    循环里面也要相应调整一下,index-1已经越界了
      

  5.   

    checkbox1不选的时候有错误么?
      

  6.   

    没啊~~checkbox1是:   是否对输出的素数排序
      

  7.   

    那就是对数组a的操作出了问题for i:=0 to index-2 do
               for j:=i+1 to index-1 do分别改为-3和-2
      

  8.   

    一般来说,这样的应用可以利用TStringList来中转遍历ListBox1,将符合要求的数据Add到TStringList中去,用TStringList的Sort方法就可以排序了然后输出到ListBox2
      

  9.   

    -3和-2还是不行啊~~TStringList是什么啊??控件还是属性啊~~我们没学过呢...
     能不能说的详细点啊~~谢谢啦:D 
      

  10.   

    var
      SL: TStringList;
      I: Integer;
    begin
      SL := TStringList.Create;
      for I := 9 downto 0 do
        SL.Add(IntToStr(I));
      SL.Sort;
      for I := 0 to SL.Count - 1 do
        ShowMessage(SL.Strings[I]);
      FreeAndNil(SL);
    end;你试试上面的程序,就基本上会用TStringList了,你可以把它当作一个字符串数组,记得先Create再用,用完记得Free