Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7613499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:10:14+00:00 2026-05-31T02:10:14+00:00

In Notepad you can Open any File and it will display the raw data

  • 0

In Notepad you can Open any File and it will display the raw data inside.

I would like to do this in a TMemo but have struggled to find out how to do this.

I managed to find this code here.

I modified it to a function and changed it slightly for my purposes:

function OpenBinaryFile(var Data; Count: Cardinal): string;
var
  Line: string[80];
  i: Cardinal;
  P: PAnsiChar;
  nStr: string[4];
  SL: TStringList;
const
  posStart = 1;
  binStart = 7;
  ascStart = 57;
begin
  P := @Data;
  Line := '';

  SL := TStringList.Create;
  try
    for i := 0 to Count - 1 do
    begin
      if (i mod 16) = 0 then
      begin
        if Length(Line) > 0 then
          SL.Add(Trim(Line));

        FillChar(Line, SizeOf(Line), ' ');
        Line[0] := Chr(72);
      end;

    if P[i] >= ' ' then
      Line[i mod 16 + ascStart] := P[i]
    else
      Line[i mod 16 + ascStart] := '.';
    end;

    SL.Add(Trim(Line));

    Result := SL.Text;
 finally
    SL.Free;
  end;
end;

It works, but it only displays in a fixed amount of characters per line, like this:

enter image description here

What do I need to change so it fills all the memo in the same way Notepad would?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:10:15+00:00Added an answer on May 31, 2026 at 2:10 am

    Well, it’s the if (i mod 16) = 0 test that is truncating the lines at 16 characters.

    I believe that Notepad does the same as this code:

    var
      i: Integer;
      s: AnsiString;
      Stream: TFileStream;
    begin
      Stream := TFileStream.Create(FileName, fmOpenRead);
      try
        SetLength(s, Stream.Size);
        if Stream.Size>0 then
          Stream.ReadBuffer(s[1], Stream.Size);
      finally
        Stream.Free;
      end;
      for i := 1 to Length(s) do
        if s[i]=#0 then
          s[i] := ' ';
      Memo1.Text := s;
    end;
    

    If you want to replace non-printable characters with '.' then you can easily do so by modifying the code above like this:

    if s[i]<#32 then
      s[i] := '.';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if I can get any message to say that
I'm trying to get my c++ program to open an sql file in notepad++.
I am making a .bat file, and I would like it to write ASCII
I would like to open a website in a user's default web browser, however
I have a file. When I open it in Notepad I see charachters in
I have some code that is reading a config file, but when I open
May be duplicate. I would like to write javascript which can execute linux command
If you open Notepad, add ten lines and resize the editor to only show
I have a costumer showing Notepad with a large set of data that looks
I want to build an notepad-style application on android that will have syntax highlighting.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.