Solved

Acces Violations

Posted on 2002-05-30
23
236 Views
Last Modified: 2010-04-04
Hi Folks,

We've got a slight problem.  One of our applications has a StringGrid in an MDI form.  Depending on the cell selected, a popup menu is modified (items enabled or disabled).  If the form is closed without making the popup appear, it works fine.  However, if the popup is visible when you click the close button (the X a the top of the form), we get an A/V.

I've removed all the code which dynamically changes the popup (removed the event), but it still does it.

Does anyone have any ideas as to what could be causing this as it's causing us a lot of grief.

Thanks for any info,


Stu
0
Comment
Question by:Stuart_Johnson
  • 13
  • 9
23 Comments
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7045811
Some more info.

If we put a button on the form and make it close the form (calling Close), we don't get an A/V.  This isn't an option though, it was just a test.

So, why would the button work and not the close (X) button at the top of the form?

Stu
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 7045844
Hi Stu,

It may be that the order of the popup closing and the sending of the close message to the form may be getting confused:

Here are some thoughts:

1. Don't free the form when it is closed (ie: don't set action := caFree). Instead call the Release method

2. Here's a kludgy idea to try as well, do this in the OnClose event:

var
  HaveClosed : Boolean;

...
Init HaveClosed to false somewhere;
...

procedure TMyForm.FormClose(Sender : TObject;
                            var action : ???);
begin
  if HaveClosed then
    action := cafree
  else
    begin
      HaveClosed := True;
      action := caNone;
      PostMessage(Handle, WM_CLOSE);
    end;
end;

Cheers,

Raymond.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7045908
Hi Ray,

Thanks for the info.  The app is an MDI App, so I have to use the Action to free the form.  Unless there is another way of freeing the form?

The code you gave worked, but I still get the A/V.

Any other clues at all?  There is now no FormDestroy (I got rid of that).  There is no OnCloseQUery either.  There is code in the FormClose, but it's only setting a few booleans which exist on the apps main form.  Even if I comment all this code out, I still get the same problem.

This is really driving me mad.  I need to get this working in 2 hours.  I have no idea why it's doing it at all.  Granted, the form in the app has been blown out of proportion (it was never ment to do half the things its doing now).

Thanks mate.

Stu
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 7045926
Where is the AV occuring?

Raymond.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7045930
I honestly don't know.  I can't find it.  It appears to be after the form is freed, but there is no code in the main application which detects that the form is no longer running.

If I put a break point in the FormClose event, it goes all the way through to the "end" and then I get the A/V.  There is no re-entry code after that, so I don't know what's going on.

Stu
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 7045952
Where is the AV occuring?

Raymond.
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 200 total points
ID: 7045957
Opps, ignore that!

Do you compile the VCL source into your app? If not include $(Delphi)\vcl\source into your search path, rebuild and see where the AV breaks at...

Cheers,

Raymond.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7045958
Is that an accidental double post, Ray?

Stu
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7046006
Hi Ray,

I'm just running it now.  Tracing from the FormClose forward.  I'll let you know what the problem is when I find it.

Cheers

Stu
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 7046016
Stu,

You should be able to let the critter run and get execution stopping in the source when the AV occurs...

Raymond.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7046066
OK.  I've found the source of the problem.

If you right-click on the grid, the menu appears.  If you click on the close button, when the menu closes, (get this) the MouseUp event is fired!  How does that work?  Strange..

I'm just trying to work out what's going on.  This is a project I've only just started working on, so I'm not familar with it.

Stu
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 12

Expert Comment

by:rwilson032697
ID: 7046074
That is strange! I have noticed in the past that the MouseDown, MouseClick, MouseUp order can occur in that order, when you might expect it to do Down, Up, Click!

Now you have found it I image killing it should be simple :-)

Cheers,

Raymond.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7046091
Nope.  Not that simple worst luck.  It's just not going to go away.  I've fixed it SORT OF.  It only does it every now and then.  Even if it does it once, it's once too often.

Do you know of any code I can use to make the menu close up again?  I'm really clutching at straws here, but I don't know what else to try.  I think we're on the right path with trapping the errors.  I've been given a time repreave, so I can spend more time trying to debug it.  I'll keep going down the path you suggested above.

Thanks so much for you help Ray.  I really appreciate it!

Stu
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7046105
OK.  Here is an interesting thing.  This same code works PERFECTLY in our version 1.4 application which was writtin in Delphi 3 Ent.  From 1.5 onwards it's stuffed (we're now on version 1.9) and 1.5+ has been done in Delphi 5.

Could the be ANYTHING at all in D5 which could cause this sort of thing?  I don't think I'm using any of the updates - would it be worth downloading and installing them?

Stu
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 7046118
The popup menu should close all by itself when you click on the close button for the MDI form.

Take a look at the TPopupMenu.Popup method. It calls TrackPopupMenu, a Win32 API function that handles the display etc of the menu. You could put a breakpoint after this to see it come back when you click on the close button for the form.

Cheers,

Raymond.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 7046157
There is quite a lot of change between D3 and D5 (why not d6??), though nothing comes to mind which would cause this.

It would certainly be a good idea to get the D5 updates installed (not that it guarantees a fix of course).

Another kludge you could look at is setting a flag in the close event that the mouse up event can look at...

Cheers,

Raymond.


0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7046199
how about checking the forms state on the popups OnPopup event ?
like :

procedure TForm1.myPopupPopUp(Sender: TObject);
begin
  if csDestroying in ComponentState then exit;
  // if you do any procesing here at all
end;

that saved me lots of AVs :)

how do you create the popup  ?
dinamically ? do you create any of it's items dinamically ?
also on the forms Close event try closing the menu
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7046268
OK, after much rooting around (take that literally if you please), I fixed the problem.

In the FormCloseQuery, I set the grid's OnMouseUp event to nil and the problem went away.  It's now going perfectly.

Thank you so much for you help, Ray.  You solved a lot of headaches.

Stu
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7046270
Hi Lee,

Thank-you too for your contribution.  The error didn't happen when the popup popped up, but when it was closing back down again.

Stu
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7046271
Hi Lee,

Thank-you too for your contribution.  The error didn't happen when the popup popped up, but when it was closing back down again.

Stu
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 7046295
Hi Stu,

Thanks for the points! Hopefully the new project won't throw too many of these nasties at you!

Cheers,

Raymond.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7046299
No worries, Ray.  Thanks for the help.

Stu
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 7046300
No worries, Ray.  Thanks for the help.

Stu
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now