<div dir="ltr">2013/2/4 silvioprog <span dir="ltr"><<a href="mailto:silvioprog@gmail.com" target="_blank">silvioprog@gmail.com</a>></span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<div dir="ltr">2013/2/4 Vincent Snijders <span dir="ltr"><<a href="mailto:vincent.snijders@gmail.com" target="_blank">vincent.snijders@gmail.com</a>></span><br><div class="gmail_extra"><div><div class="gmail_quote">


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
2013/2/4 silvioprog <<a href="mailto:silvioprog@gmail.com" target="_blank">silvioprog@gmail.com</a>>:<br>
<div>> 2013/2/4 David Knaack <<a href="mailto:davidknaack@gmail.com" target="_blank">davidknaack@gmail.com</a>><br>
>><br>
>> I may not understand the scope of your question, but could you use the<br>
>> swap function?<br>
>><br>
>> <a href="http://www.freepascal.org/docs-html/rtl/system/swap.html" target="_blank">http://www.freepascal.org/docs-html/rtl/system/swap.html</a><br>
>><br>
>> Like so (edited in email, not compile checked):<br>
>><br>
>> function ReadMWord(AStream: TStream): Word;<br>
>>   var<br>
>>     MW: Word<br>
>>   begin<br>
>>     AStream.Read(MW, SizeOf(Word));<br>
>>     Result := Swap(MW);<br>
>>   end;<br>
><br>
><br>
> Perfect! :)<br>
><br>
> Thank you very much!<br>
<br>
</div>Instead of swap, you may use beton, so that it works on big endian cpus too:<br>
<a href="http://www.freepascal.org/docs-html/rtl/system/beton.html" target="_blank">http://www.freepascal.org/docs-html/rtl/system/beton.html</a><br>
<span><font color="#888888"><br>
Vincent<br></font></span></blockquote></div><div class="gmail_extra"><br></div></div>Many thanks guy, worked like a charm too! :) I'll use BEtoN instead Swap.</div></div></blockquote></div><div class="gmail_extra"><br>


</div><div class="gmail_extra">Oops... And this is the full code:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra"><div class="gmail_extra">program project1;</div><div class="gmail_extra">

<br></div><div class="gmail_extra">{$mode objfpc}{$H+}</div><div class="gmail_extra"><br></div><div class="gmail_extra">uses</div><div class="gmail_extra">  Classes,</div><div class="gmail_extra">  SysUtils;</div><div class="gmail_extra">

<br></div><div class="gmail_extra">  function ReadInt(AStream: TStream): Word;</div><div class="gmail_extra">  begin</div><div class="gmail_extra">    Result := 0;</div><div class="gmail_extra">    AStream.Read(Result, SizeOf(Word));</div>

<div class="gmail_extra">    Result := BEtoN(Result);</div><div class="gmail_extra">  end;</div><div class="gmail_extra"><br></div><div class="gmail_extra">var</div><div class="gmail_extra">  VFile: TFileStream;</div><div class="gmail_extra">

begin</div><div class="gmail_extra">  VFile := TFileStream.Create('data.ascii', fmOpenRead or fmShareDenyWrite);</div><div class="gmail_extra">  try</div><div class="gmail_extra">    VFile.Seek(2, 0);</div><div class="gmail_extra">

    WriteLn(ReadInt(VFile));</div><div class="gmail_extra">    VFile.Seek(6, 0);</div><div class="gmail_extra">    WriteLn(ReadInt(VFile));</div><div class="gmail_extra">  finally</div><div class="gmail_extra">    VFile.Free;</div>

<div class="gmail_extra">  end;</div><div class="gmail_extra">end.</div></div></div><div class="gmail_extra"><br></div>-- <br>Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a>
</div></div>