Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need OnCreate event for TFrame children

I have problem with Frames and inheritance in Delphi 7.

Suppose I define a Frame with visible=false (on design time). Now I embed this frame in some Form, and set visible=true on the embedded instance of the frame inside the form (also on design time).

Now suppose I want to initialize the embedded frame according to its visible property that was set in design time. The problem is that simple overriding the frame's constructor doesn't work, since inside the constructor I always get visible=false (I guess because the DFM properties hasn't been read yet). I also don't want to put the initialization code inside the Form unit, because this logic belongs only to the Frame.

What is your best rule of thumb for dealing with such cases?

Clarification Frame.Visible is only an example. The question is relevant for all other properties of the Frame, or its inner components, that are set in design time. For example let's say we are talking about the color of TEdit inside the Frame.

like image 929
gamliela Avatar asked Sep 01 '25 16:09

gamliela


1 Answers

You cannot write property-sensitive code in the constructor because, as you noted, the DFM properties have not necessarily been read yet when the constructor is running. Instead, override the Loaded method of your frame class and put your code there. It's called after the properties are loaded from the DFM.

Add noted, Visible won't work with that technique, but other properties will.

like image 178
Rob Kennedy Avatar answered Sep 04 '25 10:09

Rob Kennedy