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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:16:41+00:00 2026-05-31T14:16:41+00:00

I know i have posted a similar question before but i am not able

  • 0

I know i have posted a similar question before but i am not able to get it working I have this simple code :

procedure TfrmMain.srvrConnect(AContext: TIdContext); //idhttpserver on connect event
var
  S,C : String;
begin
 repeat
  s := s + AContext.Connection.Socket.ReadChar;
 until AContext.Connection.Socket.InputBufferIsEmpty = True;
 frmMain.caption := S;
 Memo1.Lines.Add(S);
end;

The strings displays ok in the memo but the caption doesn’t get updated

  • 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-31T14:16:43+00:00Added an answer on May 31, 2026 at 2:16 pm

    TIdHTTPServer is a multi-threaded component. TIdContext runs in its own worker thread. You cannot safely update the Form’s Caption (or do anything else with the UI) from outside of the main thread. You need to synchronize with the main thread, such as with the TIdSync or TIdNotify class.

    On a side note, calling ReadChar() in a loop is very inefficient, not to mention error-prone if you are using Delphi 2009+ since it cannot return data for surrogate pairs.

    Use something more like this instead;

    type
      TDataNotify = class(TIdNotify)
      protected
        Data: String;
        procedure DoNotify; override;
      public
        constructor Create(const S: String);
        class procedure DataAvailable(const S: String);
      end;
    
    constructor TDataNotify.Create(const S: String);
    begin
      inherited Create;
      Data := S;
    end;
    
    procedure TDataNotify.DoNotify;
    begin
      frmMain.Caption := Data; 
      frmMain.Memo1.Lines.Add(Data); 
    end;
    
    class procedure TDataNotify.DataAvailable(const S: String);
    begin
      Create(S).Notify;
    end;
    
    procedure TfrmMain.srvrConnect(AContext: TIdContext); //idhttpserver on connect event 
    var 
      S: String; 
    begin 
      AContext.Connection.IOHandler.CheckForDataOnSource(IdTimeoutDefault);
      if not AContext.Connection.IOHandler.InputBufferIsEmpty then
      begin
        S := AContext.Connection.IOHandler.InputBufferAsString; 
        TDataNotify.DataAvailable(S); 
      end;
    end; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know similar questions have been posed before, but I could not find a
I know similar questions have been posted before, but I have specific requirements that
I know there have been some similar questions to this, but they haven't helped
sorry if a similar question has been posted before, i didn't know what terms
I have posted a question about a similar issue before, and managed to fix
I have posted a question about a similar issue before, and managed to fix
I know this is very similar to a previous question that I had posted,
I know there have been similar questions posted but I think the issue I'm
I know people have asked similar questions, but I believe the causes of their
I know there have been a million questions asking this, but mine is different.

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.