I am using a dinamic array with block read and I keep on geting an I/O error
87. When I replace the dynamic array for a static one, then everything
works just fine. The problem is, I need to use that dynamic array.
Here is a piece of the code:
procedure Sort_UnzipFiles();
var WordBuf: array of char;
begin
S:=SearchZip.Name;
SetLength(WordBuf,50000);
AssignFile(WordFile, '\aaa\' + S);
Reset(WordFile, 1);
I:=Length(WordBuf);
BlockRead(WordFile, WordBuf, I, FileLength);
CloseFile(WordFile);
.
.
.
end; {Sort_UnzipFiles}
Any ideas?
--
------------------------------------------------------------
Joseph I. Ceasar
Senior Project Manager and IT/IS Administrator
Silent Type, Inc.
------------------------------------------------------------
> var WordBuf: array of char;
...
> SetLength(WordBuf,50000);
...
> BlockRead(WordFile, WordBuf, I, FileLength);
> Any ideas?
WordBuf is a dynamic array, so WordBuf only contains a pointer to the
actual array. The actual array starts at WordBuf[0] (actually, this means
WordBuf^[0], but that is not valid syntax here). You could use:
BlockRead(WordFile, WordBuf[0], I, FileLength);
--
Rudy Velthuis (TeamB)
A dynamic array variable is actually a pointer, whereas a static array is a
variable. I am sure there is a correct way to do this (and this isn't it),
but I would cast the reference into a pointer then deference it thus:
BlockRead(WordFile, Pointer(WordBuf)^, FileLength)
regards
Martin Lafferty