Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BlockRead not working with dynamic arrays

37 views
Skip to first unread message

Joseph I. Ceasar

unread,
May 1, 2001, 2:46:09 PM5/1/01
to
Hi all,

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

Rudy Velthuis (TeamB)

unread,
May 1, 2001, 3:14:15 PM5/1/01
to
In article <3aef04d4_2@dnews>, Joseph I. Ceasar says...

> 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)

Martin Lafferty

unread,
May 1, 2001, 3:54:35 PM5/1/01
to
> 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);
> .

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

0 new messages