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 to avoid AV in the IDE when Component are deleted

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





PostPosted: Fri Feb 06, 2004 6:41 am    Post subject: Re: How to avoid AV in the IDE when Component are deleted Reply with quote




"Asger Jørgensen" <Asger.Pnotthis (AT) AJ-World (DOT) dk> wrote


Quote:
if i delete either one of thes components i get an AV and
i have to kill the Builder from the task manager in order
to get on with my work, not good..Wink

Please show your actual code. You are most likely mismanaging your pointers
correctly.


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Feb 06, 2004 7:49 pm    Post subject: Re: How to avoid AV in the IDE when Component are deleted Reply with quote



"Asger Jørgensen" <Asger.Pnotthis (AT) AJ-World (DOT) dk> wrote


Quote:
The code i a lot bigger, but below is one getter and a setter +
the __property, i memset the FInputs[16] to 0 in the constructor.
snip


You are maintaining pointers to external component instances. At no time in
your setter method are you registering your component to be notified when
any of those external instances are freed so that you can remove your
reference to it. You did not indicate where the AV is actually occuring
(did you even step through your code yet), but you are most likely trying to
access a pointer from your array after it has already been freed since you
did not update your references.

Assuming TAJInput is derived from TComponent, you should be calling the
instance's FreeNotification() method, and then having your component
override its own inherited Notification() method. For example:

class TAJ_InputModule : public TWhatever
{
private:
TAJInput* FInputs[16];
void __fastcall setInput00(TAJInput* Value);
//...
protected:
virtual void __fastcall Notification(TComponent* AComponent,
TOperation Operation);
//...
};

void __fastcall TAJ_InputModule::setInput00(TAJInput* Value)
{
#if (__BORLANDC__ >= 0x0550)
if( FInputs[0] != NULL )
FInputs[0]->RemoveFreeNotification(this);
#endif
FInputs[0] = Value;
if( FInputs[0] != NULL )
FInputs[0]->FreeNotification(this);
}

void __fastcall TAJ_InputModule::Notification(TComponent* AComponent,
TOperation Operation)
{
if( Operation == opRemove )
{
for(int x = 0; x < 16; ++x)
{
if( FInputs[x] == AComponent )
FInputs[x] = NULL;
}
// update your component as needed...
}

// specify the name of the base class you are actually using
TWhatever::Notification(AComponent, Operation);
}


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Feb 07, 2004 1:35 am    Post subject: Re: How to avoid AV in the IDE when Component are deleted Reply with quote




"Asger Jørgensen" <Asger.Pnotthis (AT) AJ-World (DOT) dk> wrote


Quote:
I thought i did at design time when deleting one of the referenced
components.

You didn't say whether the AV was occuring in your own code or not, only
that one was occuring in general.

Quote:
The IDE might do so but i'm not

Again, have you actually stepped through your code to find out what is
actually happening?

Is your component still displayed in the Object Inspector at the time when
you delete one of the external components? Or do you ever click on your
component to display it after deleting one of the external components? If
yes to either question, then the Object Inspector is going to re-query your
properties, which in turn will access your properties, which are then
returning pointers from your array. If you do not update your array
properly, you are going to return invalid pointers to the Object Inspector.
So of course it is going to crash until that scenerio.


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Feb 07, 2004 2:56 am    Post subject: Re: How to avoid AV in the IDE when Component are deleted Reply with quote


"Asger Jørgensen" <Asger.Pnotthis (AT) AJ-World (DOT) dk> wrote


Quote:
Since it all happend when working in the IDE (no App running)
i can't step through the code.

Yes, you can. Please read the "Testing installed components" topic in the
help file.


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.