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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:21:12+00:00 2026-05-20T14:21:12+00:00

Ultimately my goal is to be able to save an array of records data

  • 0

Ultimately my goal is to be able to save an array of records data structure in a sqlite BLOB field, but in the interim I am trying to serialize an array of records and store it in a TMemoryStream. In case it may be relevant, I am using Tim Anderson’s sqlite wrapper (unicode) with Delphi 2010.

This is my array of record declaration:

type
  TPerson = array of packed record
    sCountry: string[50];
    sFullName: string[100];
    sAddress: string[100];
    sCity: string[30];
    sEmployer: string[100];
  end;

var
  MyPeople       : TPerson;

And here is the code I am currently using to serialize this array of record to a TMemoryStream. The problem is that it doesn’t work:

var
  i : integer;
  ms : TMemoryStream:
  ms2 : TMemoryStream;    
  TestPeople : TPerson;
  sldb              : TSQLiteDatabase;
begin
    ms := TMemoryStream.Create;
    ms2 := TMemoryStream.Create;
    sldb := TSQLiteDatabase.Create(slDBPath); //sldBPath is a global variable with path to sqlite db
    try
        i := Length(MyPeople);
        ms.Write(i, 4);
        ms.Write(pointer(MyPeople)^, i * sizeOf(MyPeople));
        ///
        ms2.Read(i, 4);  
        SetLength(ms2, i);
        ms2.Read(pointer(TestPeople)^, i * sizeOf(TestPeople));

        WriteLn('#############' + ms2[0].sFullName); //check if we can read data back

        sQuery := 'UPDATE PersonDirectory SET fldPersonBlob = ? WHERE id = "' + 42 + '";';
        sldb.UpdateBlob(sQuery, ms);

    finally
      ms.Free;
      ms2.Free;
      sqldb.Free;
    end;
end;

Any ideas on either how to generally serialize an array of record to a TMemoryStream, or a better way to store an array of records in a sqlite BLOB field?

  • 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-20T14:21:12+00:00Added an answer on May 20, 2026 at 2:21 pm

    Make TPerson the packed record, and declare TPersons as array of TPerson.

    type
      TPerson = packed record
        sCountry: string[50];
        sFullName: string[100];
        sAddress: string[100];
        sCity: string[30];
        sEmployer: string[100];
      end;
      TPersons = array of TPerson;
    var
      MyPeople: TPersons;
    

    This allows you to get SizeOf(TPerson) to get the right size of the record, while Length(MyPeople) will give you the length of the array. Multiply them to get the total byte size. That should get you started.

    Also note that some read and write action start from the beginning of the stream, while others continue at the current position. Setting position to 0 before copying the contents of a stream to another is sometimes needed. The documentation will mention this.

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

Sidebar

Related Questions

I am trying to get my head around a LINQ issue. The ultimate goal
This code produces a FileNotFoundException, but ultimately runs without issue: void ReadXml() { XmlSerializer
I'm trying to get an object element from my webpage using getElementById (ultimately so
A discussion happened today where a grid containing data, which ultimately had data attached
I'm currently investigating in the field of dev environment for OSGi bundles. My goal
I am trying to ultimately extract some files from a tar archive within PHP,
Ultimately, code compiles down (eventually) into instructions for a CPU. Code, however, (in my
I have a site that will ultimately support 4 languages and 2 countries (US
What I want to be able to do is alter the value= of an
I am dealing with image buffers, and I want to be able to access

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.