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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:37:40+00:00 2026-05-27T19:37:40+00:00

How can I check if the control is fully initialized ? Consider the following

  • 0

How can I check if the control is fully initialized ?
Consider the following code (I know it’s very bad practice to do this, please take it as an example)

type
  TForm1 = class(TForm)
    Memo1: TMemo;
  private
    procedure WndProc(var Message: TMessage); override;
  public
    { Public declarations }
  end;

procedure TForm1.WndProc(var Message: TMessage);
begin
{  
   I'd like to log the messages to the memo as soon 
   as it's possible so I need to find out how to
   check if the memo box is ready to use; the following
   code stuck the application, so that the form is not
   even displayed. How would you fix this code except
   "avoid using of component access in window proc" ?
}

  if Assigned(Memo1) then
    if Memo1.HandleAllocated then
      Memo1.Lines.Add('Message: ' + IntToStr(Message.Msg));

  inherited WndProc(Message);
end;

P.S. I know OutputDebugString 🙂
Thanks!

  • 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-27T19:37:40+00:00Added an answer on May 27, 2026 at 7:37 pm

    Your question rather confused me. When you said:

    log messages to the memo

    What you mean is that you want to log messages to the form by writing text to the memo.

    That approach is fraught with danger since when you write to the memo, the form gets sent messages which results in you writing to the memo and a stack overflow is the inevitable consequence.

    I managed to make your idea sort of work by putting in re-entrancy protection. I also introduced a transient non-visual string list to capture any messages that are delivered before the control is ready to display them. Once you introduce this then you no longer need to worry about finding the precise earliest moment at which it is safe to add to the memo.

    unit LoggingHack;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
    
    type
      TLoggingForm = class(TForm)
        Memo1: TMemo;
      private
        FLog: TStringList;
        FLogging: Boolean;
      protected
        procedure WndProc(var Message: TMessage); override;
      public
        destructor Destroy; override;
      end;
    
    var
      LoggingForm: TLoggingForm;
    
    implementation
    
    {$R *.dfm}
    
    { TLoggingForm }
    
    destructor TLoggingForm.Destroy;
    begin
      FreeAndNil(FLog);
      inherited;
    end;
    
    procedure TLoggingForm.WndProc(var Message: TMessage);
    var
      Msg: string;
    begin
      if not FLogging then begin
        FLogging := True;
        Try
          Msg := IntToStr(Message.Msg);
          if Assigned(Memo1) and Memo1.HandleAllocated then begin
            if Assigned(FLog) then begin
              Memo1.Lines.Assign(FLog);
              FreeAndNil(FLog);
            end;
            Memo1.Lines.Add(Msg);
          end else if not (csDestroying in ComponentState) then begin
            if not Assigned(FLog) then begin
              FLog := TStringList.Create;
            end;
            FLog.Add(Msg);
          end;
        Finally
          FLogging := False;
        End;
      end;
      inherited;
    end;
    
    end.
    
    end;
    

    The moral of the story is that you should use a more appropriate logging framework that does not interact with what you are trying to log.

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

Sidebar

Related Questions

We can check some control's string property which has been empty like following code:
With this code I can check the caret position in a textarea in firefox:
Related to this question: On postback, how can I check which control cause postback
how can i check if a user is logged in in user control with
How can I check if a Win32 Window pointer is a valid .Net Control?
Does anyone know how I can check to see if a directory is writeable
We get this error in Visual Studio 2005 and TFS very often. Can anyone
I would like to know how can I check if a html is available.
On postback, how can I check which control cause postback in Page_Init event. protected
Can check out here alt text http://51hired.com/static/problem.bmp

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.