I'm looking at a constraint error when running this code. In the debugger it halts on the 2nd line (Menu_Text...). I put the code on the RHS of the assignment into the watch window and I see no problem. It's evaluates exactly as it should.
for I in 1..This_Info_Ptr.Child_Menu_Length loop
Menu_Text := This_Info_Ptr.Child_Menu_Text_Ptr.all(I-1);
Menu_State := This_Info_Ptr.Child_Menu_States_Ptr.all(I-1);
...
The error is when I is 1. I have confirmed that this code works in the watch window:
This_Info_Ptr.Child_Menu_Text_Ptr.all(I-1)
Child_Menu_Text_Ptr and Child_Menu_States_Ptr point to arrays (of strings and enums),
How should I debug this I general? I can't see anything wrong with the code. However, my familiarity with Ada access types is limited. The ..._Ptr variables are access types.
I am using GNAT.
Assuming the arrays being indexed are all of the same dimension and have the same index type, then iterating over them should be done using the
'first
&'last
or'range
attributes.It is likely that the hand coded control of length values has a bug. Using the inbuilt functionality is safer and more reliable.