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

The Archive Base Latest Questions

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

I want a string type that is Unicode and that stores the string directly

  • 0

I want a string type that is Unicode and that stores the string directly at the adress of the variable, as is the case of the (Ansi-only) ShortString type.

I mean, if I declare a S: ShortString and let S := 'My String', then, at @S, I will find the length of the string (as one byte, so the string cannot contain more than 255 characters) followed by the ANSI-encoded string itself.

What I would like is a Unicode variant of this. That is, I want a string type such that, at @S, I will find a unsigned 32-bit integer (or a single byte would be enough, actually) containing the length of the string in bytes (or in characters, which is half the number of bytes) followed by the Unicode representation of the string. I have tried WideString, UnicodeString, and RawByteString, but they all appear only to store an adress at @S, and the actual string somewhere else (I guess this has do do with reference counting and such). Update: The most important reason for this is probably that it would be very problematic if sizeof(string) were variable.

I suspect that there is no built-in type to use, and that I have to come up with my own way of storing text the way I want (which actually is fun). Am I right?

Update
I will, among other things, need to use these strings in packed records. I also need manually to read/write these strings to files/the heap. I could live with fixed-size strings, such as <= 128 characters, and I could redesign the problem so it will work with null-terminated strings. But PChar will not work, for sizeof(PChar) = 1 – it’s merely an address.

The approach I eventually settled for was to use a static array of bytes. I will post my implementation as a solution later today.

  • 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:22:03+00:00Added an answer on May 14, 2026 at 9:22 pm

    The solution I eventually settled for is this (real-world sample – the string is, of course, the third member called “Ident”):

    TASStructMemHeader = packed record
      TotalSize: cardinal;
      MemType: TASStructMemType;
      Ident: packed array[0..63] of WideChar;
      DataSize: cardinal;
      procedure SetIdent(const AIdent: string);
      function ReadIdent: string;
    end;
    

    where

    function TASStructMemHeader.ReadIdent: string;
    begin
      result := WideCharLenToString(PWideChar(@(Ident[0])), length(Ident));
    end;
    
    procedure TASStructMemHeader.SetIdent(const AIdent: string);
    var
      i: Integer;
    begin
      if length(AIdent) > 63 then
        raise Exception.Create('Too long structure identifier.');
      FillChar(Ident[0], length(Ident) * sizeof(WideChar), 0);
      Move(AIdent[1], Ident[0], length(AIdent) * sizeof(WideChar));
    end;
    

    But then I realized that the compiler really can interpret array[0..63] of WideChar as a string, so I could simply write

      var
        MyStr: string;
    
      Ident := 'This is a sample string.';
      MyStr := Ident;
    

    Hence, after all, the answer given by Mason Wheeler above is actually the answer.

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

Sidebar

Ask A Question

Stats

  • Questions 410k
  • Answers 410k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this VBA: Range("B26,B19,B13").Select C# Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("B26,B19,B13", Type.Missing); May 15, 2026 at 7:23 am
  • Editorial Team
    Editorial Team added an answer EDIT: This is a solution using some modifications I made… May 15, 2026 at 7:23 am
  • Editorial Team
    Editorial Team added an answer I believe you're in the right path right now, but… May 15, 2026 at 7:23 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.