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

The Archive Base Latest Questions

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

I have a record that looks similar to: type TNote = record Title :

  • 0

I have a record that looks similar to:

type
  TNote = record
    Title : string;
    Note  : string;
    Index : integer;
  end;

Simple. The reason I chose to set the variables as string (as opposed to an array of chars) is that I have no idea how long those strings are going to be. They can be 1 char long, 200 or 2000.
Of course when I try to save the record to a type file (file of…) the compiler complains that I have to give a size to string.
Is there a way to overcome this? or a way to save those records to an untyped file and still maintain a sort of searchable way?

Please do not point me to possible solutions, if you know the solution please post code.
Thank you

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

    You can’t do it with a typed file. Try something like this, with a TFileStream:

    type
       TStreamEx = class helper for TStream
       public
          procedure writeString(const data: string);
          function readString: string;
          procedure writeInt(data: integer);
          function readInt: integer;
      end;
    
    function TStreamEx.readString: string;
    var
       len: integer;
       iString: UTF8String;
    begin
       self.readBuffer(len, 4);
       if len > 0 then
       begin
          setLength(iString, len);
          self.ReadBuffer(iString[1], len);
          result := string(iString);
       end;
    end;
    
    procedure TStreamEx.writeString(const data: string);
    var
       len: cardinal;
       oString: UTF8String;
    begin
       oString := UTF8String(data);
       len := length(oString);
       self.WriteBuffer(len, 4);
       if len > 0 then
          self.WriteBuffer(oString[1], len);
    end;
    
    function TStreamEx.readInt: integer;
    begin
       self.readBuffer(result, 4);
    end;
    
    procedure TStreamEx.writeInt(data: integer);
    begin
       self.WriteBuffer(data, 4);
    end;
    
    type
      TNote = record
        Title : string;
        Note  : string;
        Index : integer;
        procedure Save(stream: TStream);
      end;
    
    procedure TNote.Save(stream: TStream);
    var
       temp: TMemoryStream;
    begin
       temp := TMemoryStream.Create;
       try
          temp.writeString(Title);
          temp.writeString(Note);
          temp.writeInt(Index);
          temp.seek(0, soFromBeginning);
          stream.writeInt(temp.size);
          stream.copyFrom(temp, temp.size);
       finally
          temp.Free;
       end;
    end;
    

    I’ll leave the Load procedure to you. Same basic idea, but it shouldn’t need a temp stream. With the record size in front of each entry, you can read it and know how far to skip if you’re looking for a certain record # instead of reading the whole thing.

    EDIT: This was written specifically for versions of Delphi that use Unicode strings. On older versions, you could simplify it quite a bit.

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

Sidebar

Related Questions

I have a an XSD that looks like this (roughly) <xs:schema id=Appointment targetNamespace=http://tempuri.org/Record.xsd elementFormDefault=qualified
I have a flat-file schema that has a header and detail records. It looks
I have a record set that includes a date field, and want to determine
Let's say that I have a record in the database and that both admin
I have a recordset that contains only 1 record but I need to display
I have a table that has a processed_timestamp column -- if a record has
I have a migration in Rails that inserts a record into the database. The
I have a SQL query that is supposed to pull out a record and
I have an Access form where each record has some info that is computed
We have a tech support website/database at work that we use to record our

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.