Mit einem MemoryStream gehts auch:
Delphi-Quellcode:
function GetBinToHex(Value: TStream): string; // Analog TCustomIniFile.WriteBinaryStream;
var
Stream: TMemoryStream;
begin
SetLength(Result, (Value.Size - Value.Position) * 2);
if Length(Result) > 0 then
begin
Stream := TMemoryStream.Create;
try
Stream.CopyFrom(Value, Value.Size - Value.Position);
Stream.Position := 0;
BinToHex(PChar(Integer(Stream.Memory) + Stream.Position), PChar(Result),
Stream.Size - Stream.Position);
finally
Stream.Free;
end;
end;
end;
function BinToHexFromFile(const FileName: string): string;
var
FileStream: TFileStream;
begin
Result := '';
if FileExists(FileName) then
begin
FileStream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
FileStream.Position := 0;
Result := GetBinToHex(FileStream);
finally
FileStream.Free;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Add(BinToHexFromFile('..'));
end;