我的程序在退出时总是报告非法操作,我检查了了一下,问题出在下面这段显示子程序.找了好久没找到原因....急死了...大家帮帮忙.
delphi的非法提示:
Project hafumanPro.exe raised exception class EAccessViolation with message 'Access violation at address 00404418 in module 'HAFUMAN>EXE'.Read of address FFFFFFFF'.Process stopped.Use Step or Run to continue.
另外我这是一个显示2叉树的子程序,当最小化时,画好的树会消失,如果图的某一部分被遮住,那一部分也会小时,请问这种问题怎么解决.子程序:
procedure TForm1.Button8Click(Sender: TObject);
var
x,y,t,minwidth,maxheight,length,linewidth,i,j:integer;
a:array[1..50] of real;
tempx,tempy,tempe:real;
begin
image1.Invalidate;
image1.Update;
maxheight:=countmaxheight();
if maxheight>6 then
   begin
   showmessage('深度大于6,无法显示');
   exit;
   end
else
   begin
   if (maxheight<>1) then
      begin
      tempx:=maxheight-1;
      tempy:=ln(2);
      tempe:=exp(tempx*tempy);
      minwidth:=trunc(398/tempe-14.5);
      length:=trunc(300 div (maxheight-1)-6);
      a[maxheight-1]:=minwidth;
      for i:=maxheight-2 downto 1 do
         begin
         if i=maxheight-2 then a[i]:=minwidth+8.5
            else a[i]:=2*a[i+1]+6;
         end;
      end;
   x:=(248+(248+401)) div 2;
   y:=136+5+7;
   tree.a[tree.n-1].x:=x;
   tree.a[tree.n-1].y:=y;
   canvas.Pen.Color:=clblue;
   canvas.Ellipse(x-7,y-7,x+7,y+7);
   for i:=1 to maxheight-1 do
   begin
   linewidth:=trunc(a[i]);    
   j:=0;
   while(tree.a[j].weight<>0) do
      begin
      if(tree.a[j].height=i)then
         begin
         tree.a[tree.a[j].lchild].x:=tree.a[j].x-linewidth-5;
         tree.a[tree.a[j].lchild].y:=tree.a[j].y+length+6;
         tree.a[tree.a[j].rchild].x:=tree.a[j].x+linewidth+7;
         tree.a[tree.a[j].rchild].y:=tree.a[j].y+length+6;
         if(tree.a[j].lchild<>-1) then
            begin
            canvas.MoveTo(tree.a[j].x-7,tree.a[j].y);
            canvas.LineTo(tree.a[j].x-7-linewidth+1,tree.a[j].y);
            canvas.LineTo(tree.a[j].x-7-linewidth+1,tree.a[j].y+length-1);
            canvas.Pen.Color:=clblue;
            canvas.Ellipse(tree.a[tree.a[j].lchild].x-7,tree.a[tree.a[j].lchild].y-7,tree.a[tree.a[j].lchild].x+7,tree.a[tree.a[j].lchild].y+7);
            end;
         if(tree.a[j].rchild<>-1) then
            begin
            canvas.MoveTo(tree.a[j].x+7,tree.a[j].y);
            canvas.LineTo(tree.a[j].x+7+linewidth-1,tree.a[j].y);
            canvas.LineTo(tree.a[j].x+7+linewidth-1,tree.a[j].y+length-1);
            canvas.Pen.Color:=clblue;
            canvas.Ellipse(tree.a[tree.a[j].rchild].x-7,tree.a[tree.a[j].rchild].y-7,tree.a[tree.a[j].rchild].x+7,tree.a[tree.a[j].rchild].y+7);
            end;         end;
      j:=j+1;
      end;
   end;
end;