Board index » cppbuilder » TForm destructor gives Invalid pointer operation error

TForm destructor gives Invalid pointer operation error


2004-08-10 09:43:53 AM
cppbuilder59
Hi,
I've got a reasonably simple Form program. Its `File->Exit' menu
item runs
void __fastcall TForm1::FileExitExecute(TObject *Sender)
{
exit(0);
}
at which point I get the following error
Project myproject.exe raised exception class EInvalidPointer
with message 'Invalid pointer operation'. Process stopped.
The de{*word*81} reports that the error is in Forms.hpp at the TForm
destructor line under
class PASCALIMPLEMENTATION TForm : public TCustomForm
/* TCustomForm.Destroy */ inline __fastcall virtual ~TForm(void) { }
I doubt that the real problem is in Forms.hpp. However, I'm not quite
sure where this suggests I should start looking for problems in my code.
I don't declare my own destructors -- I just rely on the defaults.
I'm running BCB6 on XP Pro. Any suggestions on what sort of problems
might lead to the above error message (aside from my not having a whole
lot of experience with BCB)?
PS: I mistakenly posted this message (or close variant) in the
deployment newsgroup -- Hernan Tornielli suggested I used Close() above,
instead of exit(0) (thanks Hernan) and said that I should be posting
such questions here instead. Unfortunately, Close() gave the same
behaviour. Also, I hope that I'm not in trouble for (possibly dual)
posting now! If so, sorry.
Gordon Fenton
 
 

Re:TForm destructor gives Invalid pointer operation error

"Gordon Fenton" < XXXX@XXXXX.COM >wrote in message
Quote
void __fastcall TForm1::FileExitExecute(TObject *Sender)
{
exit(0);
}
**NEVER** call exit() from a VCL project. exit() is a C library function,
not a VCL function, and it is an immediate termination of the program that
does not allow the VCL to clean up after itself. If you want to terminate
the program, you should instead either close the MainForm or call
Application->Terminate().
Quote
Hernan Tornielli suggested I used Close() above, instead of exit(0)
Hernan is correct in this case.
Quote
Unfortunately, Close() gave the same behaviour.
Then your form object has probably been corrupted at some point during your
program's lifetime, which suggests a larger problem with your project.
Gambit
 

Re:TForm destructor gives Invalid pointer operation error

Hello Remy/Gambit/TeamB,
Maybe I have a special version of BC++B, but my exit(0) command
quite happily calls the derived and base destructors to `clean up after
itself', as you say (it doesn't). Perhaps your gentle recommendation
below derives from an earlier version of BC++B?
In the meantime, I am still researching the problem. Thanks for your
help (and quick response) in the interim. Don't worry yourself about it
any further, I will no doubt manage to sort it out without any more
recommendations.
Gordon
Remy Lebeau (TeamB) wrote:
Quote
"Gordon Fenton" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...


>void __fastcall TForm1::FileExitExecute(TObject *Sender)
>{
>exit(0);
>}


**NEVER** call exit() from a VCL project. exit() is a C library function,
not a VCL function, and it is an immediate termination of the program that
does not allow the VCL to clean up after itself. If you want to terminate
the program, you should instead either close the MainForm or call
Application->Terminate().


>Hernan Tornielli suggested I used Close() above, instead of exit(0)


Hernan is correct in this case.


>Unfortunately, Close() gave the same behaviour.


Then your form object has probably been corrupted at some point during your
program's lifetime, which suggests a larger problem with your project.


Gambit


 

{smallsort}

Re:TForm destructor gives Invalid pointer operation error

"Gordon Fenton" < XXXX@XXXXX.COM >wrote in message
Quote
Maybe I have a special version of BC++B, but my exit(0)
command quite happily calls the derived and base destructors
to `clean up after itself', as you say (it doesn't).
I didn't say that it doesn't call destructors. I said that it doesn't allow
the VCL to perform internal cleanups. They are different issues. Just
please trust me when I say that you should NOT call exit() in a VCL project
and leave it at that, ok?
Quote
Perhaps your gentle recommendation below derives from
an earlier version of BC++B?
No.
Quote
In the meantime, I am still researching the problem. Thanks
for your help (and quick response) in the interim. Don't worry
yourself about it any further, I will no doubt manage to sort it
out without any more recommendations.
Please show your actual code. If you do not want you show yourt actual
code, then please make a new project with minimal code that reproduces the
same issue and then show that code.
Gambit
 

Re:TForm destructor gives Invalid pointer operation error

OK, good point. exit() is out, in favour of Close().
Regarding the code, I have no problems showing it to you, but it is kind
of long, so I'll try to make a new (small) representative project that
replicates the error. My suspicion is that if I start from scratch over
like that and compare the code, I'll actually find the error.
I should tell you that this code has been ported from Borland C++ 5.0.
The converted myproject.bpr file included a `dclusr.lib' entry that I
deleted (BDB only came with dclusr.cpp, which I could compile into a
lib, but the linker didn't complain about anything missing when I just
took out the lib). I just thought of that. Is that lib significant?
Perhaps I'll check that out today.
Anyhow, thanks for your thoughts. I'll let you know what I find.
Gordon
Remy Lebeau (TeamB) wrote:
Quote
"Gordon Fenton" < XXXX@XXXXX.COM >wrote in message
news:4118a535$ XXXX@XXXXX.COM ...


>Maybe I have a special version of BC++B, but my exit(0)
>command quite happily calls the derived and base destructors
>to `clean up after itself', as you say (it doesn't).


I didn't say that it doesn't call destructors. I said that it doesn't allow
the VCL to perform internal cleanups. They are different issues. Just
please trust me when I say that you should NOT call exit() in a VCL project
and leave it at that, ok?


>Perhaps your gentle recommendation below derives from
>an earlier version of BC++B?


No.


>In the meantime, I am still researching the problem. Thanks
>for your help (and quick response) in the interim. Don't worry
>yourself about it any further, I will no doubt manage to sort it
>out without any more recommendations.


Please show your actual code. If you do not want you show yourt actual
code, then please make a new project with minimal code that reproduces the
same issue and then show that code.


Gambit