Recent

Author Topic: Variable array error  (Read 3472 times)

Degibbo

  • New Member
  • *
  • Posts: 46
Variable array error
« on: September 14, 2017, 01:52:30 am »
G'day all,
Me again - all has been going good with various projects but this problem has me stumped:

I have defined a type TByteArray [0..49] of byte.

When the following procedure is run, the variable OutArray does not seem to exist.
The error is "Cannot access memory at address 0x0".  Why?  What have I done wrong?
(The InArray is OK).

procedure TUserForm.CopyArray(InArray : TByteArray ; var OutArray : TByteArray);
var
  I : integer;
begin
  for I := 0 to 49 do
    OutArray := InArray;
end;

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Variable array error
« Reply #1 on: September 14, 2017, 02:32:26 am »
What have I done wrong?
for starters: not having your posted code between code tags...  :)

see how it reads differently when you use code tags:

Code: Pascal  [Select][+][-]
  1. procedure TUserForm.CopyArray(InArray : TByteArray ; var OutArray : TByteArray);
  2. var
  3.   I : integer;
  4. begin
  5.   for I := 0 to 49 do
  6.     OutArray[I] := InArray[I];
  7. end;
  8.  

Secondly, you should be posting code in such fashion that it is able to compile. (at the least you should be showing all relevant declarations and subroutines).

That you think you've done it right doesn't exactly guarantee that you actually have done so. Unfortunately we can't see that.

So where is your actual declaration of TByteArray and how do you call this TUserForm.CopyArray() procedure ?

bytebites

  • Hero Member
  • *****
  • Posts: 625
Re: Variable array error
« Reply #2 on: September 14, 2017, 02:38:05 pm »
Or simply

Code: Pascal  [Select][+][-]
  1. procedure TUserForm.CopyArray(InArray : TByteArray ; var OutArray : TByteArray);
  2. begin
  3.     OutArray := InArray;
  4. end;

 

TinyPortal © 2005-2018