 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Tino Uhlig Guest
|
Posted: Mon Dec 08, 2003 8:46 am Post subject: Association with components |
|
|
Hi,
I am writing a component that can get another component assigned to it
(pretty much like the TUpDown control that gets a TEdit assigned). It is not
parent or owner of the other component but uses it to do certain actions
with it (read / write the Text property). So, my question is: how do I get
to know if the associated component gets deleted - so I cant use it anymore?
Its probably an easy one, but I am a bit stuck with it.
Regards,
Tino
|
|
| Back to top |
|
 |
Todd Brylski Guest
|
Posted: Mon Dec 08, 2003 11:53 am Post subject: Re: Association with components |
|
|
"Tino Uhlig" <tino_uhlig (AT) yahoo (DOT) com> wrote
| Quote: | I am writing a component that can get another component assigned to it
(pretty much like the TUpDown control that gets a TEdit assigned). It is not
parent or owner of the other component but uses it to do certain actions
with it (read / write the Text property). So, my question is: how do I get
to know if the associated component gets deleted - so I cant use it anymore?
Its probably an easy one, but I am a bit stuck with it.
|
Override the Notification method.
Todd
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Dec 08, 2003 6:16 pm Post subject: Re: Association with components |
|
|
"Tino Uhlig" <tino_uhlig (AT) yahoo (DOT) com> wrote
| Quote: | So, my question is: how do I get to know if the associated
component gets deleted - so I cant use it anymore?
|
When an external component is associated with your component, call the
external component's FreeNotification() method. Then, in your component,
override the inherited Notification() method to receive the event so that
you can release your pointer to the external component. For example:
class TMyComp : public TWhatever
{
private:
TOtherComp *FComp;
void __fastcall SetOtherComp(TOtherComp *Value);
protected:
void __fastcall Notification(TComponent* AComponent, TOperation
Operation);
__published:
__property TOtherComp* OtherComp = {read=FComp, write=SetOtherComp};
};
void __fastcall TMyComp::Notification(TComponent* AComponent, TOperation
Operation)
{
if( (Operation == opRemove) && (AComponent == FComp) )
OtherComp = NULL;
TWhatever::Notification(AComponent, Operation);
}
void __fastcall TMyComp::SetOtherComp(TOtherComp *Value)
{
if( FComp != Value )
{
#if (__BORLANDC__ >= 0x0550 ) // bcb5 or higher
if( FComp )
FComp->RemoveFreeNotification(this);
#endif
FComp = Value;
if( FComp )
FComp->FreeNotification(this);
// update your component as needed...
}
}
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|