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 791007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:46:00+00:00 2026-05-14T21:46:00+00:00

I need to read a large (2000×2000) matrix of binary data from a file

  • 0

I need to read a large (2000×2000) matrix of binary data from a file into a dynamic array with Delphi 2010. I don’t know the dimensions until run-time.

I’ve never read raw data like this, and don’t know IEEE so I’m posting this to see if I’m on track.

I plan to use a TFileStream to read one row at a time.

I need to be able to read as many of these formats as possible:

 16-bit two's complement binary integer
 32-bit two's complement binary integer
 64-bit two's complement binary integer
 IEEE single precision floating-point

For 32-bit two’s complement, I’m thinking something like the code below. Changing to Int64 and Int16 should be straight forward. How can I read the IEEE?

Am I on the right track? Any suggestions on this code, or how to elegantly extend it for all 4 data types above? Since my post-processing will be the same after reading this data, I guess I’ll have to copy the matrix into a common format when done.

I have no problem just having four procedures (one for each data type) like the one below, but perhaps there’s an elegant way to use RTTI or buffers and then move()’s so that the same code works for all 4 datatypes?

Thanks!

  type
    TRowData = array of Int32;

   procedure ReadMatrix;
   var
     Matrix: array of TRowData;
     NumberOfRows: Cardinal;
     NumberOfCols: Cardinal;
     CurRow: Integer;
   begin
     NumberOfRows := 20; // not known until run time
     NumberOfCols := 100; // not known until run time
     SetLength(Matrix, NumberOfRows);
     for CurRow := 0 to NumberOfRows do
       begin
         SetLength(Matrix[CurRow], NumberOfCols);
         FileStream.ReadBuffer(Matrix[CurRow], NumberOfCols * SizeOf(Int32)) );
       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-14T21:46:01+00:00Added an answer on May 14, 2026 at 9:46 pm

    No, AFAIK there’s no way to use RTTI to set up multidimensional arrays. But if you’re using Delphi 2010, you should be able to use generics, like so:

    type
      TRowData<T> = array of T;
    
     procedure ReadMatrix<T>;
     var
       Matrix: array of TRowData<T>;
       NumberOfRows: Cardinal;
       NumberOfCols: Cardinal;
       CurRow: Integer;
     begin
       NumberOfRows := 20; // not known until run time
       NumberOfCols := 100; // not known until run time
       SetLength(Matrix, NumberOfRows, NumberOfCols);
       for CurRow := 0 to NumberOfRows do
         FileStream.ReadBuffer(Matrix[CurRow][0], NumberOfCols * SizeOf(T)) );
     end;
    

    This will have to be in a class, though, as Delphi 2010 doesn’t support standalone procedures with generic types. Once you’ve got this set up, you can call TWhateverClass.ReadMatrix<integer>, TWhateverClass.ReadMatrix<int64>, TWhateverClass.ReadMatrix<single>, and so on.

    Also, if you have a multidimensional array with X dimensions, you can pass X length parameters to SetLength, not just one. So use one call to SetLength(Matrix, NumberOfRows, NumberOfCols) outside the loop, instead of initializing each row separately to the same width.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.