Registriert seit: 23. Mai 2007
117 Beiträge
Delphi 2006 Professional
|
Invalid floating point operation
31. Jul 2007, 14:17
Hallo...
Es tut mit leid, dass ich hier soviel Quellcode posten muss, aber ich weiß einfach nich woran es liegt. Mein Programm stürzt einfach irgendwann ab, wenn ich das Fenster verkleinern will, ab einer bestimmten Größe schmiert er ab und alles hängt sich auf. Es kam irgendwann ma die oben genannte Fehlermeldung. Ich weiß mir nich so richtig zu helfen. Wäre toll, wenn einer mal drüber schauen könnte bzw. generell eine Idee hätte, worans liegen könnte...Dachte eiegntlich ich würd alles soweit beachten.
Dankeschön schonmal und liebe Grüße,
Laura
Delphi-Quellcode:
procedure CalculateRect(ParentID: TTreemapElementID; ARect: TRect; Layer: Integer;
CalculateHint: Boolean; MouseX: Integer; MouseY: Integer; var Path: WideString; var FrameRect: TRect;
var Caption: WideString; var Value: Integer; var ID: TTreemapElementID);
var
i: Integer;
ChildCount: Integer;
StartIndex: Integer;
EndIndex: Integer;
Orientation: Boolean;
CurrentAspect: Single;
LastAspect: Single;
CurrentX: Single;
CurrentY: Single;
CurrentX1: Single;
CurrentY1: Single;
OffsetX: Single;
OffsetY: Single;
TotalSum: Integer;
ScaleValue: Double;
TempChildCount: Integer;
AWidth: Integer;
AHeight: Integer;
TempWidth: Single;
TempHeight: Single;
TempArray: Array of TSortArray;
j: Integer;
begin
StartIndex := 0;
EndIndex := 0;
CurrentAspect := 999;
OffsetX := 0.0;
OffsetY := 0.0;
AWidth := ARect.BottomRight.X - ARect.TopLeft.X;
AHeight := ARect.BottomRight.Y - ARect.TopLeft.Y;
TempWidth := AWidth;
TempHeight := AHeight;
// keine Gleitkommazahlberechnungen, daher nich wichtig
Orientation := DrawingOrientation(TempWidth, TempHeight);
ComputeSizeArray(ParentID);
ChildCount := DoGetChildCount(ParentID);
TotalSum := SumRectangles(ParentID);
try
ScaleValue := ((AWidth * AHeight) / TotalSum) / 100
except
on EZeroDivide do
ScaleValue := 0.0;
end;
for i := 0 to ChildCount-1 do
begin
SortArray[i].SizeTemp := ScaleValue * SortArray[i].Values.ChildValue;
end;
while (EndIndex <> ChildCount) do
begin
LastAspect := SquarifiedTryLayout(StartIndex, EndIndex, Orientation, TempWidth, TempHeight);
if ((LastAspect > CurrentAspect) or (LastAspect < 1)) then
begin
CurrentX := ARect.TopLeft.X;
CurrentY := ARect.TopLeft.Y;
for i:= StartIndex to EndIndex-1 do
begin
SortArray[i].X := OffsetX + CurrentX;
SortArray[i].Y := OffsetY + CurrentY;
if (Orientation)then
CurrentY := Single(CurrentY) + Single(SortArray[i].Height)
else
CurrentX := Single(CurrentX) + Single(SortArray[i].Width);
end;//for
if (Orientation) then
OffsetX := Single(OffsetX) + Single(SortArray[StartIndex].Width)
else
OffsetY := Single(OffsetY) + Single(SortArray[StartIndex].Height);
TempWidth := AWidth - OffsetX;
TempHeight := AHeight - OffsetY;
Orientation := DrawingOrientation(TempWidth, TempHeight);
StartIndex := EndIndex;
EndIndex := StartIndex;
CurrentAspect := 999;
continue;
end//if(LastAspect>CurrentAspect)
else
begin
for i:= StartIndex to EndIndex do
begin
SortArray[i].Width := SortArray[i].TempWidth;
SortArray[i].Height := SortArray[i].TempHeight;
end;//for
CurrentAspect := LastAspect;
end;//else
EndIndex := EndIndex + 1;
end;//while(EndIndex <> ChildCount)
CurrentX1 := ARect.TopLeft.X;
CurrentY1 := ARect.TopLeft.Y;
for i:= StartIndex to EndIndex-1 do
begin
SortArray[i].X := Single(OffsetX) + Single(CurrentX1);
SortArray[i].Y := Single(OffsetY) + Single(CurrentY1);
if (Orientation) then
CurrentY1 := CurrentY1 + SortArray[i].Height
else
CurrentX1 := CurrentX1 + SortArray[i].Width;
end;//for
if(CalculateHint = False) then
SquarifiedPaintRect(Layer, ParentID)
else
begin
for i:=0 to ChildCount-1 do
begin
ARect.TopLeft := Point(Round(SortArray[i].X), Round(SortArray[i].Y));
ARect.BottomRight := Point(Round(SortArray[i].Width + SortArray[i].X), Round(SortArray[i].Height + SortArray[i].Y));
if (CheckMouseMove(MouseX, MouseY, ARect, Path, ParentID, i)) then
begin
if ((ComputeArea(ARect) <= MinimumSize) or
((ShowLeafs = False) and (SortArray[i].Values.IsFolder = False))) then
begin
FrameRect.TopLeft := Point(0,0);
FrameRect.BottomRight := Point(0,0);
Value := 0;
end
else
begin
FrameRect := ARect;
Caption := SortArray[i].Values.ChildCaption;
Value := SortArray[i].Values.ChildValue;
ID := SortArray[i].ChildID;
end;//else
exit;
end;//if(CheckMouseMove)
end;//for
end;//if(CalculateHint)
SetLength(TempArray, Length(SortArray));
for j := 0 to Length(SortArray) - 1 do
begin
TempArray[j] := SortArray[j];
end;
for i := 0 to ChildCount-1 do
begin
TempChildCount := DoGetChildCount(TempArray[i].ChildID);
if (TempChildCount >=1) then
begin
ARect.TopLeft := Point(Round(TempArray[i].X), Round(TempArray[i].Y));
ARect.BottomRight := Point(Round(TempArray[i].Width + TempArray[i].X), Round(TempArray[i].Height + TempArray[i].Y));
if (Parents) then
AddPadding(ARect);
DrawOuterRect(ARect, Layer+1, True, 2, SortArray[i].Values.ChildImageIndex, SortArray[i].Values.ChildCaption);
SquarifiedCalculateRect(TempArray[i].ChildID, ARect, Layer+1, CalculateHint, MouseX, MouseY, Path, FrameRect, Caption,
Value, ID);
end;//if(TempChildCount...)
end;//for
end;
Delphi-Quellcode:
function TCustomTreemapChart.SquarifiedTryLayout(StartIndex: Integer; EndIndex: Integer; Orientation: Boolean; TempWidth: Single;
TempHeight: Single): Single;
var
Total: Single;
Aspect: Single;
LocalWidth: Single;
LocalHeight: Single;
i: Integer;
begin
Aspect := 0.0;
Total := SumRectanglesIndex(StartIndex, EndIndex);
if (Orientation) then
begin
try
LocalWidth := Total / TempHeight * 100;
except
on EZeroDivide do
LocalWidth := 0.0;
end;
LocalHeight := TempHeight;
end//if(Orientation)
else
begin
try
LocalHeight := Total / TempWidth * 100;
except
on EZeroDivide do
LocalHeight := 0.0;
end;
LocalWidth := TempWidth;
end;//else
for i:= StartIndex to EndIndex do
begin
if (Orientation) then
begin
SortArray[i].TempWidth := LocalWidth;
try
SortArray[i].TempHeight := Single(LocalHeight) * (Single(SortArray[i].SizeTemp) / Total);
except
on EZeroDivide do
SortArray[i].TempHeight := 0.0;
end;
end//if(Orientation)
else
begin
SortArray[i].TempHeight := LocalHeight;
try
SortArray[i].TempWidth := Single(LocalWidth) * (Single(SortArray[i].SizeTemp) / Total);
except
on EZeroDivide do
SortArray[i].TempWidth := 0.0;
end;
end;//else
Aspect := AspectRatio(SortArray[i].TempWidth, SortArray[i].TempHeight);
end;//for
Result := Aspect;
end;
Delphi-Quellcode:
function TCustomTreemapChart.SumRectanglesIndex(StartIndex: Integer; EndIndex: Integer): Single;
var
i: Integer;
begin
Result := 0.0;
for i:= StartIndex to EndIndex do
begin
try
Result := Single(Result) + Single(SortArray[i].SizeTemp);
except
on EAccessViolation do
Result := 0.0;
end;//try
end;//for
end;
Delphi-Quellcode:
class function TCustomTreemapChart.AspectRatio(Width: Single; Height: Single): Single;
begin
Result := 0.0;
if ((Width > 0.0) and (Height > 0.0)) then
Result := Max(Single(Width)/Single(Height), Single(Height)/Single(Width));
end;
|