Versimpelde versie.
Zoals je ziet heb je ook variabele "S" niet nodig.
Delphi Code:
program test;
{$ifdef fpc}
{$mode objfpc}
{$h+}
{$endif}
uses
classes, sysutils;
const
FileIn = 'testfile.txt';
FileOut = 'testfile.out';
MaxChars = 3;
var
MS : TMemoryStream;
Counter : integer;
B : Byte;
begin
MS := TMemoryStream.Create;
try
// Read file as binary
MS.LoadFromFile(FileIn);
MS.Position := 0;
Counter := 0;
while MS.Position < MS.Size do
begin
MS.Read(B,1);
write('$',B.ToHexString,#32);
Inc(Counter);
if (Counter mod MaxChars = 0) then
writeln;
end;
finally
MS.Free;
end;
writeln;
WriteLn ('Finished');
end.
Output:
Code:
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test
$31 $32 $33
$34 $35 $36
$37 $38 $0D
$0A
Finished
(Mijn testfile.txt eindigt met een CarriageReturn/LineFeed, ofwel een nieuwe regel, vandaar de $0D $0A als laatste twee bytes.)
Bart
Bookmarks