这是出错的那段程序,函数声明,变量定义都在一开始就定义完了
void __fastcall TForm1::Button2Click(TObject *Sender)
{ Px1=StrToFloat(EditXbegin->Text);
Px2=StrToFloat(EditXend->Text);
Py1=StrToFloat(EditYbegin->Text);
Py2=StrToFloat(EditYend->Text);
if(Px1==Px2&&Py1==Py2)
ShowMessage( "sorry,the number you enter is wrong");//此处有问题,需要结束插补
if( line->Checked==true&&arc->Checked==false)
{x1=Px1*100;
x2=Px2*100;
y1=Py1*100;
y2=Py2*100;
Xo=(int)x1;
Xe=(int)x2;
Yo=(int)y1;
Ye=(int)y2;
Sx=panduan(Xe,Xo);
Sy=panduan(Ye,Yo);//注意,再将坐标转化为脉冲后,在坐标方向的走步是否能合作表象符合不可知!
Fx=0;
Fy=0;//终点判断位设初值
V=StrToFloat(EditV->Text);
Qi=StrToFloat(EditT->Text);
Qd=V*Qi;
FRN=V*sqr(Xe*Xe+Ye*Ye);
Qd=FRN*Qi;
OX=Xe*Qd;
OY=Ye*Qd;
if(abs(Xe-Xo)>abs(Ye-yo))C=abs(Xe-Xo);
else c=abs(Ye-yo);
X[0]=Xe;
for(i=1;i<=C;i++)
{
Lab1:
if(Fx=0)
{
if((X[i]-Xe)*Sx>0)
{OX=Xe-X[i-1];
X[i]=Xe,Fx=1;}
else goto(Lab2);
}
else goto(Lab2);
Lab2:
if(Fy=0)
{
if((Y[i]-Ye)*Sy>0)
{OY=Ye-Y[i-1];
Y[i]=Xe,Fy=1;}
else goto(Lab3);
}
else goto(Lab3);
Lab3:
if(Fx&&fFy)
break;//插补结束
else{if(Fx=0)X[i]=X[i-1]+Sx*OX;
if(Fy=0)Y[i]=Y[i-1]+Sy*OY;
}
Image1->Canvas->MoveTo(X[i-1],Y[i-1]);
Image1->Canvas->LineTo(X[i],Y[i]);
}
}
else{int l,R,X[400],Y[400],S[400],Sx,Sy,Psx,Psy;
float F,T,K;
if(Clockwise==true)
{if(Ye-Y0<0)Sx=-1;
else{ if(Ye-Y0>0)Sx=1;
else Sx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-1],Y[i-1]);
Image1->Canvas->LineTo(X[i],Y[i]);
continue;}
}
}
else
{Image1->Canvas->MoveTo(X[i-1],Y[i-1]);
Image1->Canvas->LineTo(X[i],Y[i]);
continue;}
}
else
{ Image1->Canvas->MoveTo(X[i-1],Y[i-1]);
Image1->Canvas->LineTo(X[i],Y[i]);
continue;}
}
}
}
return 0;}
//---------------------------------------------------------------------------
int panduan(int a,int b)
{int S;
if(a>=b)S=1;
else S=0;
return S;
}//象限判断,返回标志位
int sgn(float a)
{int s;
if(a>=0)s=1;
else s=-1;
return s;}