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

  • SEARCH
  • Home
  • 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 7609211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:07:03+00:00 2026-05-31T01:07:03+00:00

I am trying to make a basic Hex viewer out of a TMemo, I

  • 0

I am trying to make a basic Hex viewer out of a TMemo, I know this is probably not ideal but it will be only me personally using it so that does not really matter.

(1)

Firstly, suppose a Memo is filled with Hex information like so:

enter image description here

How could I get a count of all the text blocks shown, ignoring the white space? So using the image the result in this case would be 28.

This is what I tried and I know it is completely wrong as I am accessing the Memo lines but I don’t know how to access each character.

I cant seem to solve this simple problem 🙁

function CountWordBlocks(Memo: TMemo): Integer;
var
  i: Integer;
  vCount: Integer;
begin
  for i := 0 to Memo.Lines.Count - 1 do
  begin
    if Length(Memo.Lines.Strings[i]) = 2 then
    begin
      Inc(vCount);
    end;
  end;

  Result := vCount;
end;

Here is the code I am using to display the Hex values in the Memo:

procedure ReadFileAsHex(const AFileName: string; ADestination: TStrings);
var
  fs: TFileStream;
  buff: Byte;
  linecount: Byte;
  line: string;
begin
  linecount := 0;
  line := '';
  fs := TFileStream.Create(AFileName, fmOpenRead);

  try
    ADestination.BeginUpdate;
    try
      while fs.Position < fs.Size do
      begin
        fs.Read(buff, 1);
        line := line + IntToHex(buff, 2) + ' ';
        Inc(linecount);
        if linecount = 16 then
        begin
          ADestination.Add(line);
          line := '';
          linecount := 0;
        end;
      end;
      if Length(line) <> 0 then
        ADestination.Add(line);
    finally
      ADestination.EndUpdate;
    end;
  finally
    fs.Free;
  end;
end;

(2)

If I click onto the Memo and a text block is under the cursor, how could I know which number the selected block is out of all the others?

So using the same first image, the caret is at the top line next to 68, so the result would be 3 as it is the third text block out of 28.

This should be so easy but I cannot think clearly, I don’t have the right programming mind yet and so really struggle with basic logic and solving problems!

(3)

Finally I would like to select a block at runtime by passing a block number value. I tried this without much success:

procedure FindBlock(Memo: TMemo; BlockNumber: Integer);
var
  i: Integer;
  txt: string;
  ThisWhite, PrevWhite: boolean;
  vRead: Integer;
begin
  txt := Memo.Text;
  vRead:= 0;
  PrevWhite := True;
  for i := 1 to Length(txt) do
  begin
    ThisWhite := Character.IsWhiteSpace(txt[i]);
    if PrevWhite and not ThisWhite then
    begin
      Inc(vRead);
      PrevWhite := False;
    end;
    PrevWhite := ThisWhite;

    if vRead = BlockNumber then
    begin
      Memo.SelStart := vRead;
      Memo.SetFocus;
      Exit;
    end;
  end;
end;
  • 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-31T01:07:04+00:00Added an answer on May 31, 2026 at 1:07 am

    (1)

    This works:

    function TForm1.CountBlocks: integer;
    var
      i: Integer;
      txt: string;
      ThisWhite, PrevWhite: boolean;
    begin
      txt := Memo1.Text;
      result:= 0;
      PrevWhite := true;
      for i := 1 to Length(txt) do
      begin
        ThisWhite := Character.IsWhiteSpace(txt[i]);
        if PrevWhite and not ThisWhite then
        begin
          inc(result);
          PrevWhite := false;
        end;
        PrevWhite := ThisWhite;
      end;
    end;
    

    However, it can be optimized if more detailed information about the memo contents is available. For instance, if you know that each line consists of four blocks, then the number of blocks is simply 4*Memo1.Lines.Count. My code above will even accept blocks of different width.

    (2)

    Simply replace

    for i := 1 to Length(txt) do
    

    by

    for i := 1 to Memo1.SelStart + 1 do
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I do not know the basic in depth ...but I am trying to make
I am trying to make my own website and only know some basic HTML,
Hey guys I'm trying to make a basic calculator (polish style) but can't figure
I'm trying to figure out how make a basic GET request using Network.HTTP.simpleHTTP that
I am trying to make a program which does a very basic calculation, but
I'm trying to make a LazyList EndlessList but using a sectioned adapter...The sections will
I'm trying to make a basic (Mario style) game but my sprite(plumber) doesn't appear,
I'm trying to make a basic Windows application that builds a string out of
I'm trying to make a very basic image creator using PySide. But I'm having
I'm trying to make the rows of this table start out disabled and then

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.