<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
    <title></title>
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Hi Eric<br>
    <br>
    If it is easy to locate the end of the header block, just copy the
    data into another (memory) stream and use a TStringList
    LoadFromStream() to separate them.<br>
    <br>
    Todd.<br>
    <blockquote cite="mid:SNT128-W23C636F53812A6DF4AFA6E9F640@phx.gbl"
      type="cite">
      <style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
      <div dir="ltr">
        Thanks, Ross.
        <div><br>
        </div>
        <div>Yes, I am in fact using TFileStream and its Read method for
          the binary extraction.  </div>
        <div><br>
        </div>
        <div>For the Header, I was hoping to find an existing method
          that I could call to to extract the the CR LF terminated
          strings, however I will use your suggestion for the header
          fields rather than indexing the char buffer.<br>
          <br>
          <div>
            <hr id="stopSpelling">From: <a class="moz-txt-link-abbreviated" href="mailto:ross@stationplaylist.com">ross@stationplaylist.com</a><br>
            To: <a class="moz-txt-link-abbreviated" href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
            Date: Mon, 5 Nov 2012 17:28:12 +1300<br>
            Subject: Re: [DUG] Reading Different Types from a Binary
            File<br>
            <br>
            <style><!--
.ExternalClass p.ecxMsoNormal, .ExternalClass li.ecxMsoNormal, .ExternalClass div.ecxMsoNormal
{margin-bottom:.0001pt;font-size:12.0pt;font-family:"Times New Roman","serif";}
.ExternalClass a:link, .ExternalClass span.ecxMsoHyperlink
{color:blue;text-decoration:underline;}
.ExternalClass a:visited, .ExternalClass span.ecxMsoHyperlinkFollowed
{color:purple;text-decoration:underline;}
.ExternalClass p
{margin-right:0cm;margin-left:0cm;font-size:12.0pt;font-family:"Times New Roman","serif";}
.ExternalClass span.ecxEmailStyle18
{font-family:"Calibri","sans-serif";color:#1F497D;}
.ExternalClass .ecxMsoChpDefault
{font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;}
.ExternalClass div.ecxWordSection1
{page:WordSection1;}

--></style>
            <div class="ecxWordSection1">
              <p class="ecxMsoNormal"><span style="font-family:
                  &quot;Calibri&quot;,&quot;sans-serif&quot;; color:
                  rgb(31, 73, 125);">Personally I would use a
                  TFileStream and FS.Read(S,1) one AnsiChar at a time,
                  concatenating into an AnsiString if you want the info
                  until you have ‘</span><span style="font-size: 10pt;
                  font-family:
                  &quot;Tahoma&quot;,&quot;sans-serif&quot;;">[End]’#13#10</span><span
                  style="font-family:
                  &quot;Calibri&quot;,&quot;sans-serif&quot;; color:
                  rgb(31, 73, 125);"> in the string.</span></p>
              <p class="ecxMsoNormal"><span style="font-size: 10pt;
                  font-family:
                  &quot;Tahoma&quot;,&quot;sans-serif&quot;;"> </span></p>
              <p class="ecxMsoNormal"><span style="font-family:
                  &quot;Calibri&quot;,&quot;sans-serif&quot;; color:
                  rgb(31, 73, 125);">This will have the file pointer at
                  the start of the binary data where you can then
                  FS.Read(MyDWORD,4) or MyByte,1 etc.</span></p>
              <p class="ecxMsoNormal"><span style="font-family:
                  &quot;Calibri&quot;,&quot;sans-serif&quot;; color:
                  rgb(31, 73, 125);"> </span></p>
              <p class="ecxMsoNormal"><span style="font-family:
                  &quot;Calibri&quot;,&quot;sans-serif&quot;; color:
                  rgb(31, 73, 125);">Ross.</span></p>
              <p class="ecxMsoNormal"><span style="font-family:
                  &quot;Calibri&quot;,&quot;sans-serif&quot;; color:
                  rgb(31, 73, 125);"> </span></p>
              <div>
                <div style="border-right: medium none; border-width: 1pt
                  medium medium; border-style: solid none none;
                  border-color: rgb(181, 196, 223) -moz-use-text-color
                  -moz-use-text-color; padding: 3pt 0cm 0cm;">
                  <p class="ecxMsoNormal"><b><span style="font-size:
                        10pt; font-family:
                        &quot;Tahoma&quot;,&quot;sans-serif&quot;;"
                        lang="EN-US">From:</span></b><span
                      style="font-size: 10pt; font-family:
                      &quot;Tahoma&quot;,&quot;sans-serif&quot;;"
                      lang="EN-US"> <a class="moz-txt-link-abbreviated" href="mailto:delphi-bounces@listserver.123.net.nz">delphi-bounces@listserver.123.net.nz</a>
                      [<a class="moz-txt-link-freetext" href="mailto:delphi-bounces@listserver.123.net.nz">mailto:delphi-bounces@listserver.123.net.nz</a>] <b>On
                        Behalf Of </b>Eric A<br>
                      <b>Sent:</b> Monday, 5 November 2012 9:08 a.m.<br>
                      <b>To:</b> Delphi ListServer<br>
                      <b>Subject:</b> [DUG] Reading Different Types from
                      a Binary File</span></p>
                </div>
              </div>
              <p class="ecxMsoNormal"> </p>
              <div>
                <p class="ecxMsoNormal" style="margin-bottom: 12pt;"><span
                    style="font-size: 10pt; font-family:
                    &quot;Tahoma&quot;,&quot;sans-serif&quot;;">This is
                    probably a no-brainer to most of the DUG members,
                    especially those used to pointers ...<br>
                    <br>
                    I need to read and extract data from a binary file
                    which comprises:<br>
                    - a header with character type strings, each
                    terminated by CR LF (not nulls)<br>
                    - binary data area with a mixture of byte types,
                    word types and double word types<br>
                    - a file terminator of 0xFFFF hex<br>
                    <br>
                    The files are not huge, less than 500KB, as the
                    structure originates from old memory-constrained
                    microprocessors of the 80's.<br>
                    <br>
                    The header looks like it is based on the old INI
                    file format and is of the form:<br>
                    <br>
                    [Header]<br>
                    Created=1349233072<br>
                    Title=<br>
                    Type=D<br>
                    Version=162<br>
                    [End]<br>
                    <br>
                    The binary data area follows next.  It comprises
                    different types of data blocks, with sub blocks,
                    each of which contains either bytes, words or double
                    words of data in a pre-defined pattern or structure
                    depending on the type of data block.<br>
                    <br>
                    I can read the file into a buffer (array of Char)
                    but I currently have a chunk of somewhat ugly code
                    to parse the header and find the start position of
                    the binary data after the '[End] CR LF' string. 
                    After that I need to extract data of various types
                    depending on the specified datablock types, which I
                    though I might have to use pointers for.<br>
                    <br>
                    What's the best approach for <br>
                    a) Extracting the header strings - is there a Delphi
                    function to extract CR LF terminated character
                    sequences as strings and maintain a pointer to the
                    end of the string?<br>
                    b) Creating functions for ReadByte, ReadWord,
                    ReadDoubleWord and incrementing the pointer
                    appropriately in each case ?<br>
                    <br>
                    <br>
                    Eric</span></p>
              </div>
            </div>
            <br>
            _______________________________________________
            NZ Borland Developers Group - Delphi mailing list
            Post: <a class="moz-txt-link-abbreviated" href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a>
            Admin: <a class="moz-txt-link-freetext" href="http://delphi.org.nz/mailman/listinfo/delphi">http://delphi.org.nz/mailman/listinfo/delphi</a>
            Unsubscribe: send an email to
            <a class="moz-txt-link-abbreviated" href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject:
            unsubscribe</div>
        </div>
      </div>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: <a class="moz-txt-link-abbreviated" href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a>
Admin: <a class="moz-txt-link-freetext" href="http://delphi.org.nz/mailman/listinfo/delphi">http://delphi.org.nz/mailman/listinfo/delphi</a>
Unsubscribe: send an email to <a class="moz-txt-link-abbreviated" href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe</pre>
    </blockquote>
    <br>
    <br>
    <div class="moz-signature">-- <br>
      <i>Fortune</i> favours the <b>brave</b></div>
  </body>
</html>