Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2003-03

Arrays with Undefined Ranges.

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jon David Sawyer
I seem to remember being able to declare something like:
MyArray = Array of Byte;

Useing "MyArray" as an easy way to get a pointer to a memory location.

Now if I do something similar: tQPixelArray = Array of tQPixel; I get a compiler error telling me it Expected [ and got Array.

Is there any way of being able to declare an array without a range?

If not is there a index larger than WORD that will work with arrays? QWord will not work and for some reason the compiler does not recognize DWord

Michael Van Canneyt
to Jon David Sawyer
Jon David Sawyer wrote 9 lines
I seem to remember being able to declare something like: MyArray = Array of Byte; Useing "MyArray" as an easy way to get a pointer to a memory location. Now if I do something similar: tQPixelArray = Array of tQPixel; I get a compiler error telling me it Expected [ and got Array. Is there any way of being able to declare an array without a range?

Only in the 1.1 development compiler. The 1.0 compiler doesn't support dynamic arrays.

If not is there a index larger than WORD that will work with arrays?

Yes.

QWord will not work and for some reason the compiler does not recognize DWord

Qword is 64 bit, that will not work, but Cardinal (=DWord) should work.

But you can just as well use the 'pointer math' approach and declare

Type
  tQPixelArray = ^tQPixel;
var
  Arr : TQPixelArray;
Then
  GetMem(Arr,1000*SizeOf(tqPixel));
  Arr[0]:=..
  Arr[1]:=..
will do what you expect. Only the memory management you must do
yourself.

Michael.

Jon David Sawyer
to Michael Van Canneyt
Michael Van Canneyt wrote 44 lines
On 26 Mar 2003, Jon David Sawyer wrote: > I seem to remember being able to declare something like: > MyArray = Array of Byte; > > Useing "MyArray" as an easy way to get a pointer to a memory location. > > Now if I do something similar: tQPixelArray = Array of tQPixel; I get a > compiler error telling me it Expected [ and got Array. > > Is there any way of being able to declare an array without a range? Only in the 1.1 development compiler. The 1.0 compiler doesn't support dynamic arrays. > > If not is there a index larger than WORD that will work with arrays? Yes. > QWord will not work and for some reason the compiler does not recognize > DWord Qword is 64 bit, that will not work, but Cardinal (=DWord) should work. But you can just as well use the 'pointer math' approach and declare Type tQPixelArray = ^tQPixel; var Arr : TQPixelArray; Then GetMem(Arr,1000*SizeOf(tqPixel)); Arr[0]:=.. Arr[1]:=.. will do what you expect. Only the memory management you must do yourself. Michael.

The 'Pointer Math' is EXACTLY what I was looking for. Thank you.