freepascal - How to read byte headers of untyped files and then use and display that data when they are file streams in Free Pascal and Lazarus -


i trying learn free pascal using lazarus , 1 of pet projects involves reading 64 byte headers of particular set of untyped files cannot read , displayed using text or ascii related procedures (so cannot outputted directly memo boxes etc).

so far, have devised following code does, think, read in 64 bytes of header , using tstreams , "select directory" dialog box this, based on advice received via lazarus irc. question though how use data read buffer header? example, in headers, there sequences of 8 bytes, 16 bytes, 2 bytes , on want "work on" generate other output converted string go string grid.

some of have far based on found here written mason wheeler near end (http://stackoverflow.com/questions/455790/fast-read-write-from-file-in-delphi) shows how read in, not how use it. read (http://stackoverflow.com/questions/4309739/best-way-to-read-parse-a-untyped-binary-file-in-delphi) again, shows how read data too, not subsequently use data. guidance wamrly received! far, code below outputs single value integer numbers edit box, opposed to, say, range of 8 hexadecimal values.

ps - new programming please gentle! nothing complex.

procedure tform1.probefile(fileiterator: tfileiterator);  type  tmyheader = array[1..64] of packed record  first8bytes,  next16bytes,  next2bytes: byte;  end;  var    fi : tfileiterator;                      //file iterator class   sg : tstringgrid;   numread : smallint;   filetoprobe: tstream;   header: tmyheader;  begin   fi := tfileiterator.create;   sg := tstringgrid.create(self);     // open file , read header   filetoprobe := tfilestream.create(fileiterator.filename, fmopenread);   try     filetoprobe.seek(0, sofrombeginning);     filetoprobe.readbuffer(header, sizeof(header));     edit1.text := inttostr(header[0].first8bytes);  // outputs '0' field?  if try '10' ooutputs '29' , on       filetoprobe.free;   end;  

please forgive me if misunderstood question.

as understand there header of 64 bytes. first 8 bytes belong together, next 16 bytes , 2 bytes.

to me seems declaration header should be:

   tmyheader = packed record      first8bytes: array[0..7] of byte;        next16bytes: array [0..15] of byte;      next2bytes: array [0..1] of byte;      // add more if    end; 

this recordtype has size of 8+16+2 = 26 bytes.

your code reads header looks ok me, won't repeat that.

the next16bytes in header can retrieved, example, this:

edit1.text:= ''; // needs declaration of variable "i" integer i:= 0 15   edit1.text:= edit1.text + inttostr(header.next16bytes[i]) + '-'; 

change value of first byte in next2bytes part of header follows (again example):

header.next2bytes[0]:= 123; 

finally, write changes header of file of filetoprobe.writebuffer method.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -