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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:08:28+00:00 2026-05-23T07:08:28+00:00

Does TStringList not understand BOM? Tf1 := TFileStream.Create(LIGALOG+’liga.log’,fmOpenRead or fmShareDenyNone); str:=tstringlist.Create; str.LoadFromStream(tf1); String1:=’FStream ‘+inttostr(tf1.Size)+’/

  • 0

Does TStringList not understand BOM?

Tf1 := TFileStream.Create(LIGALOG+'liga.log',fmOpenRead or fmShareDenyNone);

str:=tstringlist.Create;
str.LoadFromStream(tf1);

String1:='FStream '+inttostr(tf1.Size)+'/ String: '+(str.Text);

If a text file is saved in UTF-8 +BOM then Str.Count=0; Str.Text=''. Without BOM all is OK.
Is it normal?

  • 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-23T07:08:28+00:00Added an answer on May 23, 2026 at 7:08 am

    If you’re using a version of Delphi prior to 2009, it doesn’t support Unicode and the BOM is meaningless to TStringList.

    If you’re using D2009 or higher (which support Unicode), you can use the overloaded TStringList.LoadFromStream(Stream: TStream; Encoding: TEncoding)if you know ahead of time what the encoding is; if you don’t, the RTL will try to figure it out using TEncoding.GetBufferEncoding. You can see the Delphi XE documentation on the topic here

    If you don’t know ahead of time, and the RTL isn’t able to figure it out from the content, you can always read the BOM yourself from the stream, and then set the Stream.Position to just after the BOM and load the TStringList from that position with the decoding you determine yourself from that BOM.

    Also, creating a TFileStream simply to then load into a TStringList is a waste; TStringList.LoadFromFile will handle the file itself, and is a lot less code if that’s all you’re going to do with the TStream.

    EDIT: After your comment, I thought I’d include a list of the BOMs I’m familiar with – there may be more I’m not aware of:

    $00 $00 $FE $FF  UTF-32, big-endian (bytes must be swapped for Windows)
    $FE $FF $00 $00  UTF-32, little-endian
    $FF $FE          UTF-16 2 byte chars little-endian
    $FE $FF          UTF-16 2 byte big-endian 
    $EF $BB $BF      Unicode UTF-8 (must be decoded before using Unicode data)
    

    (For future reference: You should indicate in either the tags or the text of your question which version of Delphi you’re using, as there are differences in the VCL and RTL between them. When it comes to things like Unicode/BOM type questions, these differences are extremely important.)

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

Sidebar

Related Questions

I am using this code to check whether TStringList is created or not: procedure
First part of the code works OK while the second (commented) does not. It
Does anybody know a way to create a keyboard shortcut for the button 'Expand
We're using ITextSharp for reasons I do not understand and we dont have the
Does Google force employees who have offers from Facebook to leave immediately?
Does anyone remember the XMP tag? What was it used for and why was
Does the Java language have delegate features, similar to how C# has support for
Does anybody know any good resources for learning how to program CIL with in-depth
Does anyone know how to get IntelliSense to work reliably when working in C/C++
Does anyone have any recommendations of tools that can be of assistance with moving

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.