Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

getting values out of arrays

array

  • Please log in to reply
4 replies to this topic

#1 kruegs35

kruegs35

    CC Lurker

  • Just Joined
  • Pip
  • 8 posts

Posted 15 October 2008 - 06:52 AM

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?
  • 0

#2 ooisootuck

ooisootuck

    CC Regular

  • Just Joined
  • PipPipPip
  • 29 posts

Posted 15 October 2008 - 04:45 PM

Hi,

Can you please post your code?

Thanks
  • 0

#3 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

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.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#4 kruegs35

kruegs35

    CC Lurker

  • Just Joined
  • Pip
  • 8 posts

Posted 16 October 2008 - 01:18 PM

I do not have the actual code with me, but I will try to give the basics.

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.
  • 0

#5 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 16 October 2008 - 01:34 PM

Try this:
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.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download