Delphi - how read filestream byte by byte? -


i'm working stream files, "out of memory" error occurred. think must read stream, byte byte. load file method:

fs := tfilestream.create("c:\a\a.avi", fmopenread or fmsharedenywrite) ; 

next reset stream position:

fs.positon:=0; 

then i'm trying read first byte of stream:

var onebyte:byte; begin  fs.read(onebyte,2); 

but doesn't work properly. mistake?

byte size 1 not 2

fs.read(onebyte, 1); 

such errors can prevented using sizeof() function

fs.read(onebyte, sizeof(onebyte)); 

on note, read returns number of bytes read indicate whether or not entire read succeeded. expected check return value deal errors.

the preferred idiom use readbuffer instead. call read , in case of error raise exception.

as @david heffernan pointed out reading file stream byte byte not efficient way. take @ buffered files (for faster disk access)


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -