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

  • Home
  • SEARCH
  • 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 8616597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:39:26+00:00 2026-06-12T05:39:26+00:00

MainForm creates some secondary Frame objects at runtime to display various option panels. Here’s

  • 0

MainForm creates some secondary Frame objects at runtime to display various option panels.

Here’s a typical constructor for one of those frame classes (they each extend TFrame):

constructor Tframe2.Create(AOwner: TComponent);
begin
    inherited;
    edTime.Text := '12:00pm'; //edTime is a TEdit control. this line is where it throws the exception
    //etc.
end;

This code worked fine in Delphi (whether or not it was the right way to do things), but the same code in Lazarus keeps throwing an EInvalidOperation exception, because the control (TEdit) has no parent “window” assigned yet (rsControlHasNoParentWindow), which actually kind of makes sense when I examine the code because the parent doesn’t appear to be getting assigned until after the constructor is called.

Here is the code in MainForm the initializes the secondary frame:

if Assigned(frame) then FreeAndNil(frame);
case Node.AbsoluteIndex of
    optInterval: frame := Tframe2.Create(Self); //here's where the constructor gets called.
    //etc
end;
frame := TframeOther.Create(Self); 
if Assigned(frame) then
begin
    frame.Parent := panOptions; //here's where Tframe2's parent gets set
    frame.Align := alClient;
end;  

So can anyone explain whether there’s any important differences between Delphi and Lazarus as far as form initialization sequence?

And what the most standard way to resolve this type of initialization order problem would be? Comparing to other languages I’m more familiar with, there might be different strategies to resolve such errors. I could add another parameter to the constructor, or if there’s a method that gets called post constructor pre-drawing it on the screen that I could override I could relocate that code, or just make a helper method and call it after setParent gets called. Any particular best practice here?

Edit]: It appears this may be specific to TEdit in some way. It looks like the lines initializing the state for checkboxes are not having the same issue. Could this just be a bug in Lazarus?

  • 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-12T05:39:28+00:00Added an answer on June 12, 2026 at 5:39 am

    After further experimentation, I have been able to solve most of the immediate problem of it crashing by adding a line to set the parent of the TEdit to be the Frame (versus setting the parent of the Frame). Like so:

    edTime.Parent := Self;
    edTime.Text := '12:00';
    

    But I’d still love to understand better why this is “sometimes” needed.

    edit: while this fixes being able to set text on a TEdit this doesn’t fix the autosizing code I have that iterates through the components and resizes any that happen to be checkboxes. Apparently the form not having it’s parent set is still “sort of” a problem.

    edit2: Adding a second parameter to the constructor and setting the parent for the entire form in the constructor seemed to eliminate the need to set the Parent for the TEdit’s entirely.

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

Sidebar

Related Questions

I have a main form, which is invisible and at some point creates a
I have some JavaScript that creates Forward and Back buttons. However, I need to
My current project creates UI by WPF at runtime. Everything works well. The only
I have a form MainForm which is a Windows Forms form that contains many
I have the following code: public Mainform() { ... // scheduler scheduler.DoWork += new
I have a form, MainForm, which was working just fine and dandy until earlier
The Scenario I have a windows forms application containing a MAINFORM with a listbox
Winforms-How can I make dialog boxes appear centered on MainForm? That is as opposed
Will there normally only be one instance of MainForm? I need to hold it
Perhaps this has something to do with it being the mainForm, but I'll ask

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.