John wrote:
Why is this syntax used.
typedef TComponent inherited;
inherited::Notification .....
Instaed of.
TComponent::Notification .....
It mimics what Delphi component do in C++. If you look at any of the native
VCL .hpp files, you will see that all components have an 'inherited' typedef.
It helps make code more self-documenting when you can see 'inherited::Notification(...)'
instead of 'TComponent::Notification(...)'. It also helps protect your code
if you ever change the parent class that you derive from. All you have to
do it change the typedef accordingly, instead of having to hunt through your
component's code changing all of the references to the old parent class.
Also, in your reply you defined a SetCTSIndicator as follows.
<snip>
Whereas my code simply defines the CTSIndicator property as follows.
<snip>
I would be interested in knowing why the RemoveFreeNotification and
FreeNotification are used.
That is the key to making safe references to external components. You must
explicitly register to receive a notification when the referenced component
is freed before your own component is freed, so that you can set your reference
to NULL. FreeNotification() enables that notification, and RemoveFreeNotification()
disables it. Your code was not do that registration, which is why your code
was crashing when trying to access a component that had already been freed.
you were not being told the component was freed, so your reference was not
reset to NULL.
--
Remy Lebeau (TeamB)
Connect with Us