OC DelGuy,
I've built a form using your .pas file. I made some minor changes (mainly introducing a paintbox component so the form's canvas was not used - this should have to effect).
The first error I encountered was when clicking on the canvas I got a range check error pointing to the following line in procedure blank:
Boxes[(d.X-5) div SqSize,(d.Y-50) div SqSize]:=i;
Since boxes are a array [0..21,0..21] you should check the numbers before using them; with something like
var ax,ay : integer;
...
ax := (d.x-5) div sqSize;
ay := (d.y-50) div sqSize;
if (ax in [0..21]) and (ay in [0..21]) then
boxes[ax,ay] := i
else
showmessage(format('There is an error! ax=%d; ay=%d; they should be 0..21',[ax,ay]));
I believe this is the error that jamie pointed out earlier.
Note that I made these variables (ax & ay) integers to allow them to be out of the 0..21 range...
Using a paintbox, may mean that you can start drawing the puzzle @ 0,0 which might simplify all this!
cheers
S.
EDIT: the valid range (in pixels) to get [0..21] using your formula is:
x = -22..620
y = 23..665 that is very strange!
EDIT 2:
I am going through your code - I haven't found any particular issues so far.
One possible (minor error) is on line 90 of your code:
+IntToStr(y+1+SqSize*(d.Y-5) div SqSize)+')';
everywhere else (I've seen so far) you have "d.y-50"; so the "d.y-5" might be a typo?