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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:46:47+00:00 2026-05-27T13:46:47+00:00

How to encode TIdBytes to Base64 string (not AnsiString) ? ASocket.IOHandler.CheckForDataOnSource(5); if not ASocket.Socket.InputBufferIsEmpty

  • 0

How to encode TIdBytes to Base64 string (not AnsiString) ?

  ASocket.IOHandler.CheckForDataOnSource(5);

  if not ASocket.Socket.InputBufferIsEmpty then
  begin
    ASocket.Socket.InputBuffer.ExtractToBytes(data);
    // here I need to encode data to base64 string, how ? I don't need AnsiString!!
    // var s:string;
    s := EncodeBase64(data, Length(data)); // but it will be AnsiString :(

Or how to send AnsiString via AContext.Connection.Socket.Write() ?

Compiler saying Implicit string cast from ‘AnsiString’ to ‘string’

“data” variable contains UTF-8 data from website.

  • 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-27T13:46:48+00:00Added an answer on May 27, 2026 at 1:46 pm

    You can use Indy’s TIdEncoderMIME class to encode String, TStream, and TIdByte data to base64 (and TIdDecoderMIME to decode from base64 back to String, TStream, or TIdBytes), eg:

    s := TIdEncoderMIME.EncodeBytes(data);
    

    As for sending AnsiString data, Indy in D2009+ simply does not have any TIdIOHandler.Write() overloads for handling AnsiString data at all, only UnicodeString data. To send an AnsiString as-is, you can either:

    1) copy the AnsiString into a TIdBytes using RawToBytes() and then call TIdIOHandler.Write(TIdBytes):

    var
      as: AnsiString;
    begin
      as := ...;
      AContext.Connection.IOHandler.Write(RawToBytes(as[1], Length(as)));
    end;
    

    2) copy the AnsiString data into a TStream and then call TIdIOHandler.Write(TStream):

    var
      as: AnsiString;
      strm: TStream;
    begin
      strm := TMemoryStream.Create;
      try
        strm.WriteBuffer(as[1], Length(as));
        AContext.Connection.IOHandler.Write(strm);
      finally
        strm.Free;
      end;
    end;
    

    Or:

    var
      as: AnsiString;
      strm: TStream;
    begin
      as := ...;
      strm := TIdMemoryBufferStream.Create(as[1], Length(as));
      try
        AContext.Connection.IOHandler.Write(strm);
      finally
        strm.Free;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to encode a 100KB+ string as base64 in VBA. Are there any
I'm trying to encode and decode a base64 string. It works fine normally, but
I want to base64 encode data to put it in a URL and then
I want to encode an image into a string using the base64 module. I've
I need to encode/decode UTF-16 byte arrays to and from java.lang.String . The byte
How can I encode the Unicode character U+0048 (H), say, in a PowerShell string?
I need to simply encode a string variable (my api key) so that is
How can I encode an integer with base 36 in Python and then decode
I use JSON to encode an array, and I get a string like this:
How do i encode all chars in a string. Example : A = %32

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.