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 

Re: How do I override Event of SubComponent

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





PostPosted: Wed Aug 13, 2003 2:45 pm    Post subject: Re: How do I override Event of SubComponent Reply with quote



"Herwig Huber (TeamBeer)" <herwig.huber (AT) teambeer (DOT) net> wrote

Quote:
Hi,

TDBGrid contains the following sub-components:
DBGrid->DataSource->DataSet

Is it possible to override the AfterCancel() event of TDataSet from
TDBGrid?


Yes, just not favorable.


Quote:
I tried the following, It compiles, but it doesn't work...
snip
__fastcall TMyDBGrid::TMyDBGrid(TComponent* Owner) : TDBGrid(Owner)
{
this->DataSource->DataSet->AfterCancel = Cancel;
}


This is dangerous code. At this point (ie. inside the constructor) the
properties of your component do not have their values yet. These values are
defined in the dfm resource. The properties are not streamed into your
component yet, while the constructor executes. However, the VCL streaming
system calls TComponent::Loaded(), after the dfm resource is entirely read,
on each component created during the streaming of a dfm resource. That is
the moment you can be sure that the properties have their values. But you
blatantly assume that DataSource is set and that it has its DataSet property
set. This does not have to be the case and thus can result in a NULL
pointer crash. So, at least you should anticipate the fact these pointers
may be NULL.

Still, IMHO you need to find another way to be notified of the 'AfterCancel'
event. The end-users of TMyDBGrid will not be able to use the AfterCancel
once they link it to the grid. I would not expect that if I'd use a
TDBGrid-like component. Futhermore, what happens if the DataSet of the
DataSource is changed?

Internally TCustomDBGrid (ancestor for TDBGrid) uses a TGridDataLink
(derived from TDataLink) to respond to changes in the underlying dataset. I
guess you need a similar approach to be able to respond to the 'AfterCancel'
event in a proper way.


Ralph



Back to top
Herwig Huber (TeamBeer)
Guest





PostPosted: Wed Aug 13, 2003 8:27 pm    Post subject: Re: How do I override Event of SubComponent Reply with quote



Dear Ralph,

First of all thank you very much for your explanations.
I made several tests with all your suggestions and now I realize it's
probably better to go another way :)

I also played around with TGridDataLink but I didn't get very far. I decided
to go a completly different way.
Thanks again. You preserved me of wasting more time on this.

Herwig


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.