Okay maybe someone can help explain this...

I wrote an app using JEDI's Direct X 8.1 headers. Now the app works fine, however upon exit the app crashes under Windows 2000, and it seems to be a pointer issue. I've narrowed down the code section that apparently causes the problem. I'm hoping someone can tell me why it does.

[pascal][background=#FFFFFF][normal=#000080][number=#FF0000][string=#0000FF][comment=#8080FF][reserved=#000000]
//Create associated DirectInput devices
for iCount := 0 to (FJoyList.Count - 1) do begin
SetLength(FJoyDevice, Length(FJoyDevice) + 1);
FDirectInput.CreateDevice(PGUID(FJoyList.Objects[iCount])^, FJoyDevice[iCount], nil);
FJoyDevice[iCount].SetDataFormat(@c_dfDIJoystick2);
FJoyDevice[iCount].SetCooperativeLevel(Handle, DISCL_EXCLUSIVE or DISCL_FOREGROUND);
//SetLength(FJoyCaps, Length(FJoyCaps) + 1);
//FJoyCaps[iCount].dwSize := SizeOf(TDIDevCaps);
//FJoyDevice[iCount].GetCapabilities(FJoyCaps[iCount]);
DevNum := iCount;
FJoyDevice[iCount].EnumObjects(EnumInputAxis, nil, DIDFT_AXIS);
FJoyDevice[iCount].Acquire;
end;

[/pascal]

The three commented lines...
[pascal][background=#FFFFFF][normal=#000080][number=#FF0000][string=#0000FF][comment=#8080FF][reserved=#000000]
//SetLength(FJoyCaps, Length(FJoyCaps) + 1);
//FJoyCaps[iCount].dwSize := SizeOf(TDIDevCaps);
//FJoyDevice[iCount].GetCapabilities(FJoyCaps[iCount]);

[/pascal]

when commented allow for perfect operation. However when uncommented they cause the crash as explained above. I can't figure out why. It seems to surround FJoyCaps which is declared globally as:

[pascal][background=#FFFFFF][normal=#000080][number=#FF0000][string=#0000FF][comment=#8080FF][reserved=#000000]
VAR
FJoyCaps: array of TDIDevCaps;

[/pascal]

I've tried setting FJoyCaps := nil; at the end of the procedure, but that doesn't seem to help. Any ideas? This is the only place in my code where I currently use FJoyCaps. And I don't want to proceed until I figure out why this is causing the application to crash on exit.