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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With