<div class="gmail_quote"><div class="gmail_quote"><div><div><div class="h5"><div style="font-family:Tahoma;font-size:10pt">Hi All,</div><div style="font-family:Tahoma;font-size:10pt"><br></div><div style="font-family:Tahoma;font-size:10pt">
I am having a problem with a strange run-time AV error. See the link to the Lazarus project.</div>
<div style="font-family:Tahoma;font-size:10pt"><br></div><font face="Tahoma" size="2">Download link: </font><br><font face="Tahoma" size="2"><a href="http://hotfile.com/dl/115480488/6b7a8ed/dtm_maker_001.zip.html" target="_blank">http://hotfile.com/dl/115480488/6b7a8ed/dtm_maker_001.zip.html</a></font><br>
<br><div style="font-family:Tahoma;font-size:10pt">The problem is in the QSort procedure:</div><div style="font-family:Tahoma;font-size:10pt"><br></div><div><div><font face="Tahoma" size="2">Procedure QSort( Var island_single_array : island_single_type;</font></div>
<div><font face="Tahoma" size="2"> left, right : integer);</font></div><div><font face="Tahoma" size="2"> Var</font></div><div><font face="Tahoma" size="2"> d : island_single_type;</font></div><div><font face="Tahoma" size="2"> pivot,</font></div>
<div><font face="Tahoma" size="2"> lower1,</font></div><div><font face="Tahoma" size="2"> upper1 :integer;</font></div><div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2"> begin</font></div>
<div><font face="Tahoma" size="2"> lower1 := left;</font></div><div><font face="Tahoma" size="2">// ^^^^^^ AV run-time exception on above line.</font></div><div><font face="Tahoma" size="2"> upper1 := right;</font></div>
<div><font face="Tahoma" size="2"> pivot := island_single_array[left].location_number;</font></div><div><font face="Tahoma" size="2"> While (left < right) do</font></div><div><font face="Tahoma" size="2"> Begin</font></div>
<div><font face="Tahoma" size="2"> Case SortType of</font></div><div><font face="Tahoma" size="2"> ascending : begin</font></div><div><font face="Tahoma" size="2"> While (island_single_array[right].location_number >= pivot) and (left < right) do</font></div>
<div><font face="Tahoma" size="2"> dec(right);</font></div><div><font face="Tahoma" size="2"> if (left <> right) then</font></div><div><font face="Tahoma" size="2"> begin</font></div>
<div><font face="Tahoma" size="2"> swap(island_single_array[left],island_single_array[right]);</font></div><div><font face="Tahoma" size="2"> inc(left);</font></div><div><font face="Tahoma" size="2"> end; </font></div>
<div><font face="Tahoma" size="2"> While (island_single_array[left].location_number <= pivot) and (left < right) do</font></div><div><font face="Tahoma" size="2"> inc(left);</font></div>
<div><font face="Tahoma" size="2"> if (left <> right) then</font></div><div><font face="Tahoma" size="2"> begin</font></div><div><font face="Tahoma" size="2"> swap(island_single_array[left],island_single_array[right]);</font></div>
<div><font face="Tahoma" size="2"> dec(right);</font></div><div><font face="Tahoma" size="2"> end; </font></div><div><font face="Tahoma" size="2"> end;</font></div>
<div><font face="Tahoma" size="2"> end; // case</font></div><div><font face="Tahoma" size="2"> end; // while</font></div><div><font face="Tahoma" size="2"> pivot := island_single_array[left].location_number;</font></div>
<div><font face="Tahoma" size="2"> left := lower1;</font></div><div><font face="Tahoma" size="2"> right := upper1;</font></div><div><font face="Tahoma" size="2"> if left < pivot then</font></div><div><font face="Tahoma" size="2"> QSort(island_single_array,left,pivot-1);</font></div>
<div><font face="Tahoma" size="2"> if right > pivot then</font></div><div><font face="Tahoma" size="2"> QSort(island_single_array,pivot+1,right);</font></div><div><font face="Tahoma" size="2"> end; { QSort }</font></div>
<div><font face="Tahoma" size="2">{--------------------------------------------------------------------}</font></div><div><font face="Tahoma" size="2"><br></font></div><div><font face="Tahoma" size="2">procedure QuickSort( Var island_single_array : island_single_type;</font></div>
<div><font face="Tahoma" size="2"> Size : integer);</font></div><div><font face="Tahoma" size="2">begin</font></div><div><font face="Tahoma" size="2"> QSort( island_single_array, 1, Size );</font></div><div><font face="Tahoma" size="2">end;</font></div>
<div><font face="Tahoma" size="2">{--------------------------------------------------------------------}</font></div></div><div style="font-family:Tahoma;font-size:10pt"><br></div><div style="font-family:Tahoma;font-size:10pt">
The AV exception error occurs after the project is run then the user selects File / Save and the QuickSort procedure is called which then calls Qsort.</div><div style="font-family:Tahoma;font-size:10pt"> The error is occurring on:</div>
<div style="font-family:Tahoma;font-size:10pt"><br></div></div></div><div style="font-family:Tahoma;font-size:10pt"><div style="text-indent:0px !important;font-family:'Times New Roman';font-size:medium"><font face="Tahoma" size="2" style="text-indent:0px !important"> lower1 := left;</font></div>
<div><font face="Tahoma" size="2" style="text-indent:0px !important"><br></font></div><div><font face="Tahoma" size="2" style="text-indent:0px !important">which are both integers. Lower1 (which was renamed just in case of a name conflict with the 'lower' string function) is ??? (unassigned) and left is 1. I see no problem with this statement and it is a mystery to me why I am getting an AV exception error.</font></div>
<div><font face="Tahoma" size="2" style="text-indent:0px !important"><br></font></div><div><font face="Tahoma" size="2" style="text-indent:0px !important">Maybe someone here with better debugging skills can tell me why is this happening and how to fix it.</font></div>
<div><font face="Tahoma" size="2" style="text-indent:0px !important"><br></font></div><div><font face="Tahoma" size="2" style="text-indent:0px !important">Best Regards,</font></div><div><font face="Tahoma" size="2" style="text-indent:0px !important">Peter / pew</font></div>
</div></div></div>
</div><br>