BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Association with components

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
Tino Uhlig
Guest





PostPosted: Mon Dec 08, 2003 8:46 am    Post subject: Association with components Reply with quote



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





PostPosted: Mon Dec 08, 2003 11:53 am    Post subject: Re: Association with components Reply with quote



"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





PostPosted: Mon Dec 08, 2003 6:16 pm    Post subject: Re: Association with components Reply with quote




"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.