Jump to content
aehimself

Custom component ParentBackground property resets to false

Recommended Posts

Hello,

 

We have a custom component derived from Delphi's standard TPanel. What I realized is that the ParentBackground property resets to False each time the form is opened in the Delphi IDE (no saving is required, it automatically updates the DFM).

There are no mentions / changes made to this property in the component's code and the situation does not change even if I add this published property:

    property ParentBackground stored true default True;

I found an old topic about OldCreateOrder behaving the same way, but the proposed solution (remove the ParentBackground = False from the DFM with a text editor) only works until the form is reopened again - then it will automatically reset to False and update the DFM immediately without saving.

I'll keep digging and investigating but if anyone has experience with this please do not hesitate to share the solution 🙂

 

Thanks!

Share this post


Link to post

Would going up to TCustomPanel help in changing the default?

 

Otherwise blame it on styles :classic_sad:

Share this post


Link to post

Are you setting the property to True in the constructor?

 

The stored true just means that the value shall be written to the DFM, while the default True indicates the value which can be omitted while storing. This both settings are a bit contradicting or at least one of them is superfluous.

 

Neither of them does anything to the value of the property. 

 

Share this post


Link to post

So, the issue had nothing to do with the panel, but a label on it... and by replacing it from TLabel to TcxLabel to be precise.

 

There was a section in the constructor which looked like this:

With TLabel.Create Do
Begin
  // [...]
  If criteria Then
    Color := clRed;
End;

This was fine but in the moment someone changed it with cxLabel (which has no public .Color property) that one line immediately turned ParentBackground off on the panel as it changed it's color instead of the labels.

 

This is one reason I hate With blocks 😞

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×