//p:指针数组 (ppbtarray=array [0..999] of pbytearray,存储BMP图像的像素扫描结果
//lplab:二维数组plab=array [0..1999,0..1999] of boolean
//width:bmp.width
//heigh:bmp.heigh
//x,y:当前坐标
//m_lianxushu:连续点计数
//lianxushu:离散点阀值
function DeleteScaterJudge(P:ppbtarray;lplab:plab;width,heigh,x,y,M_lianxushu,lianxushu:Integer):Boolean;
 begin
     if M_lianxushu>lianxushu then
     begin
     result:=True;
     //lianxushu:=lianxushu+1;
     Inc(lianxushu);
     lplab[X,Y]:=True;
     end;
     Result:=False;
     if M_lianxushu>lianxushu then
     Result:=True
     else if (x<width) and (y<heigh) then
     //开始进入递归
     begin
       //下面
       if (p[Y+1][x]=0)and not(lplab[Y+1,x]) and (y-1>0) and (x-1>0)  then
       begin
         DeleteScaterJudge(p,lplab,width,heigh,x,y+1,M_lianxushu,lianxushu);
         if M_lianxushu>lianxushu then
         Result:=True;
       end;
       //左面
       if (p[y][x-1]=0) and not(lplab[y,x-1]) and (y-1>0) and (x-1>0)  then
       begin
         DeleteScaterJudge(p,lplab,width,heigh,x-1,y,M_lianxushu,lianxushu);
         if M_lianxushu>lianxushu then
         Result:=true
       end;
       //上面
        if (p[y-1][x]=0) and not(lplab[y-1,x]) and (y-1>0) and (x-1>0)  then
       begin
         DeleteScaterJudge(p,lplab,width,heigh,x,y-1,M_lianxushu,lianxushu);
         if M_lianxushu>lianxushu then
         Result:=true
       end;
       //右面
       if (p[y][x+1]=0) and not(lplab[y,x+1]) and (y-1>0) and (x-1>0)  then
       begin
         DeleteScaterJudge(p,lplab,width,heigh,x+1,y,M_lianxushu,lianxushu);
         if M_lianxushu>lianxushu then
         Result:=true
       end;
       //左上
        if (p[y-1][x-1]=0) and not(lplab[y-1,x-1]) and (y-1>0) and (x-1>0)  then
       begin
         DeleteScaterJudge(p,lplab,width,heigh,x-1,y-1,M_lianxushu,lianxushu);
         if M_lianxushu>lianxushu then
         Result:=true
       end;
       //左下
       if (p[y+1][x-1]=0) and not(lplab[y+1,x-1]) and (y-1>0) and (x-1>0)  then
       begin
         DeleteScaterJudge(p,lplab,width,heigh,x-1,y+1,M_lianxushu,lianxushu);
         if M_lianxushu>lianxushu then
         Result:=true
       end;
       //右上
         if (p[y-1][x+1]=0) and not(lplab[y-1,x+1]) and (y-1>0) and (x-1>0)  then
       begin
         DeleteScaterJudge(p,lplab,width,heigh,x+1,y-1,M_lianxushu,lianxushu);
         if M_lianxushu>lianxushu then
         Result:=true
       end;
       //右下
        if (p[y+1][x+1]=0) and not(lplab[y+1,x+1]) and (y-1>0) and (x-1>0)  then
       begin
         DeleteScaterJudge(p,lplab,width,heigh,x+1,y+1,M_lianxushu,lianxushu);
         if M_lianxushu>lianxushu then
         Result:=true
       end;
     end;
 end;调用函数时出现stack overflow的错误,请高手们指点一下
里面的错误请高手们指点一下,万分感谢

解决方案 »

  1.   

    stack overflow  堆栈溢出。
    不要用递归就可解决堆栈溢出问题了。 ^_^
    默认的栈只有1M/2M(根据编译器设置),不够用的时候当然出现stack overflow了。要么换个算法,要么就自己模拟堆栈。
      

  2.   

    Stack Overflow一般有两个原因:
    1. 算法错误
    2. 局部变量所占空间过大你可以先尝试更改一些函数原型:
    function DeleteScaterJudge(P:ppbtarray;const lplab: array of array of Boolean;width,heigh,x,y,M_lianxushu,lianxushu:Integer):Boolean;