I'm using the write method to directly write pixels
which is an array of array[(R, G, B)] of byte;
.
The pixels
is properly allocated like so: setlength(pixels, 750000);
what I do is as follows:
f := TFileStream.create(FileName, fmCreate);
written := f.write(pixels, 750000);
The problem is that the write method returns 0, videlicet it didn't write a byte from pixels
.
With some tests, I've discovered that it copies only up to about 20000 bytes, certainly not more than 30000 and the moment I give it more to write, it doesn't.. and returns 0.
I am new to Pascal, but I cannot find a solution to this unpleasant problem. So what am I doing wrong ?
The first parameter of stream.write is a so called formal parameter, like stream.write(const buf;size:integer) or so.
The compiler takes the address of whatever you pass to it and gives that to the procedure. Because you use an array without borders for the first level (array of array..) it is an dynamic array so a pointer under the hood.
If you pass the array to it, you actually pass the memory location where the pointer is stored. Solution: pass the first element, pixels[0] which is the location of the data.