type testlist=record
  id:integer;
  so:integer;
  name:array[0..255] of  Char;
  x:single;
  y:single;
  z:single;
  p:single;
  end;MyList:Array [0..999] of testlist;定义一个testlist类型的结构,包含1000个testlist的数组MyList
每2~5秒要根据x y z的数计算距离p,根据p的大小进行排序选出最小的这样的情况,是应该把MyList定义为全局变量,每次使用前把MyList内的数据全部清0
还是把MyList定义为局部变量,每次使用的时候生成用完自动释放呢?考虑效率和资源,哪种方法更合适些啊?PS:Delphi 7使用全局变量会有“意想不到”的结果么?感觉偶尔会出现某些全局变量异常的消失或者变成0……

解决方案 »

  1.   

    以前做的一个程序里出现的,就是在全局变量的位置定义了Myint:integer;   MyBool:Boolean;
    通过一个Button1来修改MyBool为True或者False。
    一个函数内通过调用ReadProcessMemory读取XXX地址的值放进Myint。(可以肯定XXX地址内有值并且>0)
    程序里有这么一段:
    MyFun();       //这个是给Myint赋值,且Myint>0
    if (MyBool=True)and(Myint>0) then .........
    点击Button1把MyBool设置为True,然后运行上面的代码,结果if...的结果为False
    仅在上面那段代码内加入一句showmessage,程序其他地方一个字母都不修改
    MyFun();       //这个是给Myint赋值,且Myint>0
    showmessage(inttostr(onlinestat)+'/'+inttostr(Mymoney));
    if (MyBool=True)and(Myint>0) then .........
    结果if...的结果为True了
      

  2.   

    showmessage(inttostr(onlinestat)+'/'+inttostr(Mymoney));
    应该是
    showmessage(inttostr(MyBool)+'/'+inttostr(Myint));
    还专门测试了一下,语法没错,这俩变量名复制过来倒忘改了
      

  3.   

        for num:=0 to 999 do begin
        MyList[num].id :=0;
        MyList[num].so :=0;
        MyList[num].name :='';
        MyList[num].x :=0;
        MyList[num].y :=0;
        MyList[num].z :=0;
        MyList[num].p :=0;
        end;清空数组,除了上面这种方法,还有更快捷的方法了么?
      

  4.   

    FillChar(MyList, SizeOf(MyList), 0)肯定是你自己的程序有问题