I am having some trouble with arrays. I want to set a variable equal to a value in an array as it goes through a loop. The array and the variable are declared as integers. When I check the value of the variable while stepping through the code, the variable is listed as unaccessible. However, if I declare the variable as a string and do an IntToStr with the array value, I can get a value in the variable. Any reason for this? Is there a way to pull the values from an array as integers?
getting values out of arrays
Started by kruegs35, Oct 15 2008 06:52 AM
4 replies to this topic
#1
Posted 15 October 2008 - 06:52 AM
|
|
|
#2
Posted 15 October 2008 - 04:45 PM
#3
Posted 16 October 2008 - 07:48 AM
Your variable will have to be of the same data type as the array's elements. Without seeing your code, it's hard to see what may be going on.
#4
Posted 16 October 2008 - 01:18 PM
I do not have the actual code with me, but I will try to give the basics.
When I step through the code and follow the local variables, the value for x would say "unaccessible due to optimization". However, if I declare x as a string and type x:= IntToStr(MyArray[i]), I will get the value out of the array as a string.
var i: integer; x: integer; MyArray: array[0..5] of integer; begin for i = 0 to 5 do begin x := MyArray[i]; end;
When I step through the code and follow the local variables, the value for x would say "unaccessible due to optimization". However, if I declare x as a string and type x:= IntToStr(MyArray[i]), I will get the value out of the array as a string.
#5
Posted 16 October 2008 - 01:34 PM
Try this:
Delphi's debugger won't let you see an uninitialized variable, and since the for loop just kinda sits there, you never get a chance to see the value of x. You should be inspecting the value of x on the "x := x;" line.
var
i: integer;
x: integer;
MyArray: array[0..5] of integer;
begin
for i = 0 to 5 do begin
begin
x := MyArray[i];
x := x;
end;
end;
Delphi's debugger won't let you see an uninitialized variable, and since the for loop just kinda sits there, you never get a chance to see the value of x. You should be inspecting the value of x on the "x := x;" line.


Sign In
Create Account

Back to top









