浮点是没有精确相等的, if (FProject.FPrjParam.XMax = FProject.FPrjParam.XMin) then 应该改为 if 0.000001>abs(FProject.FPrjParam.XMax - FProject.FPrjParam.XMin) then
sz_haitao同志说的没错,但进行两个浮点相等的判断应该不会引起异常,顶多是执行结果不准确。 另外,我将代码改成你说的进行了调试,结果在 if 0.000001>abs(FProject.FPrjParam.XMax - FProject.FPrjParam.XMin) then 这句话,又引起了相同的异常,还是Invalid floating point operation
这个异常不是发生在除法运算,而是发生在赋值。这里面的FProject.FPrjParam.XMax 和 FProject.FPrjParam.XMin 都是Integer。而且,另外一个诡异的地方是,这个函数只在另一个特定的函数中调用时才异常,在其他函数中调用时不发生异常。这是我最郁闷的地方。是在看不出有什么不对的地方procedure TImageDrawer.CreateVelCurve(xyz: Byte; bInst: Boolean); var i,scrx,scry:Integer; dx,dy,dz:Double; begin //初始化 if FProject = nil then exit; if Length(FProject.FXSeg[xyz]) = 0 then exit; SetLength(FCurvePoint,0); SetLength(FCurvePoint,Length(FProject.FXSeg[xyz])*2); for i:=0 to Length(FProject.FXSeg[xyz])-1 do begin dx:=FProject.FXSeg[xyz][i].X1;dy:=0;dz:=0; scrx:=0;scry:=0; WrdToScr(dx,dy,dz,scrx,scry); 到了这里就异常了。 FCurvePoint[i*2].X:=scrx;......而在其他的调用此函数的地方,却不会异常,例如: procedure TImageDrawer.CreateAxis; var iCount,i,iFlag,iy:integer; xStart,dK,dM,dVel:Double; tmpStr:String; begin for i:=0 to 5 do SetLength(FAxis[i],0); if FProject = nil then exit; if FProject.FPrjParam.XStep=0 then FProject.FPrjParam.XStep:=1; iCount:=0; SetLength(FAxis[0],iCount); xStart:=Floor(FProject.FPrjParam.XMin) mod 5; i:=Floor(FProject.FPrjParam.XMin - xStart); while i<= (FProject.FPrjParam.XMax) do begin Inc(iCount); SetLength(FAxis[0],iCount); WrdToScr(i,FProject.FPrjParam.YMax,0,FAxis[0][iCount-1].X1,FAxis[0][iCount-1].Y1); 这里调用,就不会异常。 ......是在是搞不懂了。
if (FProject.FPrjParam.XMax = FProject.FPrjParam.XMin) then
应该改为
if 0.000001>abs(FProject.FPrjParam.XMax - FProject.FPrjParam.XMin) then
另外,我将代码改成你说的进行了调试,结果在 if 0.000001>abs(FProject.FPrjParam.XMax - FProject.FPrjParam.XMin) then 这句话,又引起了相同的异常,还是Invalid floating point operation
var
i,scrx,scry:Integer;
dx,dy,dz:Double;
begin
//初始化
if FProject = nil then exit;
if Length(FProject.FXSeg[xyz]) = 0 then exit;
SetLength(FCurvePoint,0);
SetLength(FCurvePoint,Length(FProject.FXSeg[xyz])*2); for i:=0 to Length(FProject.FXSeg[xyz])-1 do
begin
dx:=FProject.FXSeg[xyz][i].X1;dy:=0;dz:=0;
scrx:=0;scry:=0;
WrdToScr(dx,dy,dz,scrx,scry); 到了这里就异常了。
FCurvePoint[i*2].X:=scrx;......而在其他的调用此函数的地方,却不会异常,例如:
procedure TImageDrawer.CreateAxis;
var
iCount,i,iFlag,iy:integer;
xStart,dK,dM,dVel:Double;
tmpStr:String;
begin
for i:=0 to 5 do
SetLength(FAxis[i],0);
if FProject = nil then exit;
if FProject.FPrjParam.XStep=0 then
FProject.FPrjParam.XStep:=1;
iCount:=0;
SetLength(FAxis[0],iCount); xStart:=Floor(FProject.FPrjParam.XMin) mod 5;
i:=Floor(FProject.FPrjParam.XMin - xStart);
while i<= (FProject.FPrjParam.XMax) do
begin
Inc(iCount);
SetLength(FAxis[0],iCount);
WrdToScr(i,FProject.FPrjParam.YMax,0,FAxis[0][iCount-1].X1,FAxis[0][iCount-1].Y1);
这里调用,就不会异常。
......是在是搞不懂了。
此处加断点, 查看各对象或属性是否正常.