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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:49:58+00:00 2026-06-02T00:49:58+00:00

I have an error that is confusing the hell out of me. The following

  • 0

I have an error that is confusing the hell out of me. The following code sends a line from a TidTCPClient to a TidTCPServer. The first time it executes, it works perfectly. The second time it executes, and every time after that, it adds a line break to the start of every string. What am I missing? (I know it does it in an odd way, but the list of clients is necessary in the full code)

   procedure TClientForm.ButtonSendStringClick(Sender: TObject);
    var
      I: integer;
      List: TList;
    begin
      List := ClientList.LockList;
      try
       for I := 0 to (List.Count- 1) do
        begin
          TidTCPClient(List[I]).IOHandler.WriteLn('Hello'+'|x|');
        end;
      finally
       ClientList.UnlockList;
      end;
      Edit1.Text := '';
    end;

    procedure TClientForm.IdTCPServer1Execute(AContext: TIdContext);
    var
    LLine: string;
    begin
    LLine := Acontext.Connection.IOHandler.ReadLn('|x|');
    OutputDebugString(PChar(LLine));
    end;
  • 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-06-02T00:49:59+00:00Added an answer on June 2, 2026 at 12:49 am

    WriteLn() appends a CRLF to the end of the string you pass to it, but ReadLn() stops reading when it encounters the terminator string that you specify. So you are sending 'Hello|x|#13#10' but you are only reading 'Hello|x|', leaving #13#10 in the socket buffer for the next read to grab.

    To solve your problem, you have two choices:

    1) If you want to keep using a custom terminator in ReadLn(), change WriteLn() to Write() so the implicit CRLF is not sent anymore. No change is needed in your ReadLn() call.

    Write('Hello|x|');
    LLine := ReadLn('|x|');
    

    2) Stop using a custom terminator altogether. Pass just your main string by itself to WriteLn() and let it append a CRLF, then do not pass any terminator to ReadLn() as its default terminator is LF (which includes handling for CRLF).

    WriteLn('Hello');
    LLine := ReadLn();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this error that is keeping me from moving forward. I basically have
This is the second time I have got confusing results from the modulo operator,
I have some code that's currently giving me an error, because recur can only
I have this weird situation that i have encountered for the first time and
I have an odd error that you guys will hopefully be able to help
I have a silly error that I am unable to resolve. I try to
I have a javascript error that occurs on my site, Im pretty sure I
I have a syntax error that I don't know how to fix. This is
I have a WCF error handler that uses the IErrorHandler interface. In the HandleError
I have to debug some error that is db related and have been continuously

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.