Delphi Reading File at a Specific Address

This question is very important because I am at a very basic level. I need to read the contents of a file with the extension *.pam. It is not common that a file created by a specific program has a fixed size of xx KB. It has several numbers and meanings.

I need to read this file and therefore I will use TStreamReader. Of course, I need to know the structure of the file, but I do not. By the way, I have a photo above, which is part of a table with useful information:

enter image description here

The meaning is the following: after you open the file, go to a specific address and get the data. For example, at 0x30 I can find data on "Move 1 Current PP". My question is: how do I go to the given address?

procedure TForm1.Button1Click(Sender: TObject);
var sw: TStreamReader;
begin

 Memo1.Clear;    
 sw := TStreamReader.Create('C:\aaa\myfile.pam', TEncoding.UTF8);
 try

  sw.Position := 0;

 finally
  sw.Free;
 end;

, - Seek Position, , . ,

while not(sw.EndOfStream) do
 begin
  //read...
 end;

. ? , Seek, . .

+6
1

( ), - .

TFileStream . procedure ReadBuffer() , , TBytes. EReadError, .

var
  fn: TFileName;
  fs: TFileStream;
  b: byte;
  bf: array[0..3] of word;
  ReadResult: integer;
begin
  fn := 'c:\tmp\MyMagicalFile.pam';
  fs := TFileStream.Create(fn, fmOpenRead or fmShareDenyWrite);
  try
    fs.Seek($28, soFromBeginning);    // move to offset $28 in the file
    fs.ReadBuffer(bf, 8);             // read 4 x 2 bytes into buffer (bf)
                                      // fs.Position is at this point at $30
    fs.ReadBuffer(b, 1);              // read one byte (at offset $30) into the buffer (b)
  finally
    fs.free;
  end;
  // use b and bf as needed
end;

, Seek(). ( ). SeekOptions soFromBeginning, soFromCurrent soFromEnd.   . System.Classes.TFileStream.

+5

All Articles