Reputation: 6053
I have an odd issue with TChromeTabs. I know it must be something simple, but I can't figure out what needs to be done to fix it.
When I initially drop the TChromeTabs control on a form it is completely transparent. If I cut the control then paste it back to the form the contents are displayed correctly. The contents also appear if I close, then re-open the form.
As I have no idea why this is happening I can't really give you any code samples. However, you can download the source code here: http://code.google.com/p/delphi-chrome-tabs/downloads/list.
Upvotes: 1
Views: 606
Reputation: 163357
Your control doesn't paint itself because you disable painting. You call BeginUpdate
in the constructor, and you don't call EndUpdate
until the Loaded
method is called. But Loaded
is only called when loading a control from a persisted state. Usually, we think of that as being when the control is loaded from a DFM file, but the IDE uses the same technique to allow putting controls on the clipboard.
You haven't noticed this before because, apparently, you only test your control by opening a pre-made demo project. The demo project has a control in its DFM file, so the only code path you exercise is the DFM case. You don't exercise the path where the constructor is called directly — when the control is first dropped on a form, or when the control is created "dynamically" in code.
To fix this, begin by getting rid of the BeginUpdate
call in your constructor. Instead, to check whether your control is still in the process of being constructed, check csCreating in ControlState
.
You can also get rid of your stsLoading
state. Delphi already gives you that with the csLoading
bit of ComponentState
. Besides, your use of stsLoading
is wrong since you set it in the constructor, just like you do with BeginUpdate
.
Instead of relying on Loaded
being called, you might wish to move certain code into the AfterConstruction
method. Put code there that needs to run after your component is created but that has nothing to do with loading properties from a DFM (or other persistence source). I'm not sure I see anything in your Loaded
method that really belongs there. Nearly all of it should be able to occur in the constructor.
You should also be aware of the CreateWnd
method. It's called when your control's window handle gets allocated. That's where you should start allowing paint operations to occur. When you don't have a window handle, you have nothing to paint to.
Upvotes: 4