unit main;
...
function ShowBinary(
var Data: Pointer; Count: Cardinal): TStrings;
implementation
{$R *.dfm}
procedure TForm1.readBtClick(Sender: TObject);
var Stream: TFileStream;
begin
Stream := TFileStream.Create('
D:\Test.txt', fmOpenRead
or fmShareDenyNone);
try
Stream.Seek(0, soFromBeginning);
Stream.
Read(Data[0], 128);
Stream.Position := 0;
Memo1.Lines.AddStrings(ShowBinary(Stream.Memory, Stream.Size));
finally
FreeAndNil (Stream);
end;
end;
// ShowBinary stammt von [url]http://www.swissdelphicenter.com/de/showcode.php?id=944[/url]
// Wurde nur leicht modifiziert um TStrings zurück zu geben...
function ShowBinary(
var Data: Pointer; Count: Cardinal): TStrings;
var
line:
string[80];
i: Cardinal;
p: PChar;
nStr:
string[4];
const
posStart = 1;
binStart = 7;
ascStart = 57;
HexChars: PChar = '
0123456789ABCDEF';
begin
result := TStringList.Create;
p := @Data;
line := '
';
for i := 0
to Count - 1
do begin
if (i
mod 16) = 0
then begin
if Length(line) > 0
then
result.Add(line);
FillChar(line, SizeOf(line), '
');
line[0] := Chr(72);
nStr := Format('
%4.4X', [i]);
Move(nStr[1], line[posStart], Length(nStr));
line[posStart + 4] := '
:';
end;
if p[i] >= '
'
then
line[i
mod 16 + ascStart] := p[i]
else
line[i
mod 16 + ascStart] := '
.';
line[binStart + 3 * (i
mod 16)] := HexChars[(Ord(p[i])
shr 4)
and $F];
line[binStart + 3 * (i
mod 16) + 1] := HexChars[Ord(p[i])
and $F];
end;
result.Add(line);
end;