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 

Deleting COM object

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (ActiveX)
View previous topic :: View next topic  
Author Message
LarryJ
Guest





PostPosted: Fri Mar 09, 2007 5:13 pm    Post subject: Deleting COM object Reply with quote



Destroying my COM object is causing an exception when I exit my application.
When I exit my program I am getting a "Debugger Exception Notification" that
stops in the file "system.pas" on, "procedure TObject.Free;" This is line
8314 Below shows how I declare, create and destroy the COM object. I have
TC.Unbind(); in the OnClose() event which is where I normally free all
resources. . If the COM object is not created, and destroyed then this
exception does not occur. When the project settings are no debugger and no
CodeGuard this exception appears as a generic access violation message. What
am I doing wrong here?


// Declare
TCOM_cTC2000 TC;

// Create
HRESULT hr = TC.CreateInstance( CLSID_cTC2000 );

// Destroy
if( TC ){
TC.Unbind();
}

// Debugger Exception Notification
procedure TObject.Free;
begin
if Self <> nil then
Destroy;
end;


Thanks
Larry Johnson.
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Mar 09, 2007 11:30 pm    Post subject: Re: Deleting COM object Reply with quote



"LarryJ" <LarryJ33 (AT) austin (DOT) rr.com> wrote in message
news:45f1412c$1 (AT) newsgroups (DOT) borland.com...

Quote:
What am I doing wrong here?

Nothing at all, so the error has to be something else. What else are
you doing with the COM object? Are you using any other interfaces
from it? Notification sinks, maybe?


Gambit
Back to top
LarryJ
Guest





PostPosted: Sat Mar 10, 2007 9:10 am    Post subject: Re: Deleting COM object Reply with quote



When I place a break point in the FormClose() and use F8 to step through the
code until the program is closed there is no access violation and no
Debugger Exception. If I just close the program the Debugger Exception is
given.

When I Unbind in FormClose() do I need to pause and wait for the computer
to process the Unbind before continuing on with the close process?

I have never seen this behavior before but it occurs like this each time.

Thanks
Larry Johnson.


"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:45f199c0 (AT) newsgroups (DOT) borland.com...
>
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sun Mar 11, 2007 12:57 am    Post subject: Re: Deleting COM object Reply with quote

"LarryJ" <LarryJ33 (AT) austin (DOT) rr.com> wrote in message
news:45f24b16$1 (AT) newsgroups (DOT) borland.com...

Quote:
When I Unbind in FormClose() do I need to pause and wait for
the computer to process the Unbind before continuing on with
the close process?

No.

Quote:
I have never seen this behavior before but it occurs like this each
time.


Then something else is going on. TComInterface is not derived from
TObject, so the fact that you are getting an error in TObject suggests
that TComInterface is not responsible for the error. The only way it
could be is if the TComInterface is a member of your TForm, the
offending TObject that is crashing is the TForm object, and the
TComInterface's internal memory has been mistakenly overwritten so
that its destructor thinks the interface point is still assigned when
it really isn't.


Gambit
Back to top
LarryJ
Guest





PostPosted: Mon Mar 12, 2007 5:46 pm    Post subject: Re: Deleting COM object Reply with quote

Here is the unbelieveable situation!

In my FormCloseQuery() I use the Application->MessageBox(...) as seen below.
If my app has created the COM object and then runs this
Application->MessageBox(...) in FormCloseQuery() when the program moves to
cleanup all the memory it will try to run "procedure TObject.Free;" and free
a memory location that is invalid. This causes a series of EAccess
Violation as the program closes and the Debugger Exception Notification is
shown.

I found that if I create the COM object and then my app hits ANY
Application->MessageBox(...) before closing, when the program closes this
same EAccess Violation will occur. So there seems to be a connection between
my COM object and Application->MessageBox(...) . I have no idea how to
explain this behavior.


\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
int ExitCode=0;
msg1 = "Save Charts Before Exit";

ExitCode = Application->MessageBox(msg1.c_str(), "Warning",
MB_YESNOCANCEL|MB_ICONWARNING);
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/


HRESULT hr = TC.CreateInstance( CLSID_cTC2000 );

Thanks
Larry



"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:45f2ffab$1 (AT) newsgroups (DOT) borland.com...
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Mar 12, 2007 10:21 pm    Post subject: Re: Deleting COM object Reply with quote

"LarryJ" <LarryJ33 (AT) austin (DOT) rr.com> wrote in message
news:45f53d8d$1 (AT) newsgroups (DOT) borland.com...

Quote:
I found that if I create the COM object and then my app hits ANY
Application->MessageBox(...) before closing, when the program
closes this same EAccess Violation will occur. So there seems to
be a connection between my COM object and
Application->MessageBox(...) . I have no idea how to explain
this behavior.

MessageBox() runs a message queue internally. The only possibility I
can think of is if you have a message-based event handler somewhere
that is screwing around with memory, such as freeing a pointer
somewhere but not NULL'ing it so it tries to be freed a second time
later on. It is REALLY hard to diagnose your problem with the very
limited code snippets you have shown so far.


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (ActiveX) 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.