Board index » cppbuilder » SendMessage() in OnActivate raises the exception...

SendMessage() in OnActivate raises the exception...


2004-02-03 11:06:34 PM
cppbuilder63
Hi,
I wanted to make my own 'Tip of the day' info dialog as
an independed module. That means - it has to be included
(#include), created (new), called (Tip->ShowTip()) and
destroyed (delete) when not needed anymore. That's all Ok.
As usually that dialog has 'Show tips on startup' check box.
I wanted to inform the main form that something has changed
(checked/unchecked) via SendMessage() mechanism and so to
pass the responsibility of saving configuration changes to
WndProc and main form.
Function 'ShowTip()' should be executed after main form
creation. I think I have no alternative than to put it
in FormActivate(). The problem is (I think) that WndProc
is not ready to receive anything while not left FormActivate
function - so raises some exception.
If I try to call 'ShowTip()' from somewhere else (suppose
from some menu button) everything is Ok.
What is the problem and what should I do?
Vladimir.
 
 

Re:SendMessage() in OnActivate raises the exception...

"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
Quote
Function 'ShowTip()' should be executed after main
form creation. I think I have no alternative than to put
it in FormActivate().
Not true. There are many ways to handle it. I myself prefer to post a
custom message to the form via PostMessage() and then perform any delayed
initializations when the message is processed. Is it important to use
PostMessage() instead of SendMessage() for this message so that the
processing is delayed until the application is actually finished
initializing itself and is actually running the main message queue.
Quote
The problem is (I think) that WndProc is not ready to
receive anything while not left FormActivate function
- so raises some exception.
What is the EXACT error message of the exception? Please be more specific.
Gambit
 

Re:SendMessage() in OnActivate raises the exception...

Quote
>The problem is (I think) that WndProc is not ready to
>receive anything while not left FormActivate function
>- so raises some exception.

What is the EXACT error message of the exception? Please be more
specific.
Sorry, I expressed wrong. It was classic 'Access Violation...' that AFAIK
mainly
indicates invalid pointer access.
Maybe this causes the problem - I send message something like this:
SendMessage( Application->MainForm->Handle, ... ). I use this to avoid
directly addressing some specific form (Form1, MainForm, InitialForm...)
because in that case my module is not independent.
Just to say again: this works fine when the message is sent after
OnActivate,
for example via "Help / Tip of the Day" menuitem.
I haven't tried PostMessage() now because I have no BCB installed on
this PC, but I'll try tomorrow. Still I think I tried once with PostMessage
with no success - but let's wait tomorrow to check.
 

{smallsort}

Re:SendMessage() in OnActivate raises the exception...

"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
Quote
Maybe this causes the problem - I send message something
like this:
SendMessage( Application->MainForm->Handle, ... ).
There is nothing wrong with doing it that way. Your AV has to be related to
something else. Please show your actual code.
Gambit
 

Re:SendMessage() in OnActivate raises the exception...

Quote
There is nothing wrong with doing it that way. Your AV has to be related
to
something else. Please show your actual code.
Dear Remy,
I implemented my new module (TMyTipOfTheDay) in a sample application
and it works perfectly.
When implemented in my 'master' app the AV appears. I tried today to detach
all the subsystems from my 'master' app step by step to find out what causes
such an unexpected behavior. Unfortunately I haven't enough time to detach
all
the modules (about 20 subsystems with summary cca 100 units). I detached
ALMOST all and the problem yet persists, so I'll continue tomorrow.
I'm committing this post to you just to please you not to forget this
problem
because it's of a great importance to me.
Vladimir.
 

Re:SendMessage() in OnActivate raises the exception...

Quote
There is nothing wrong with doing it that way. Your AV has to be related
to
something else. Please show your actual code.
Dear Remy,
After two days of searching what causes the Access Violation
when SendMessage() from inside OnActivete() I found the problem.
My main form (say Form1) had a property 'Visible' set to 'true'
at design time. I cannot imagine how is this involved with my
SendMessage() - but obviously is...
To be honest I never noticed that this properly has to be 'false'
by default, and I cannot remember when I changed it and why.
Vladimir.