Hi all, This is my week for solving problems! I'm the poor sod who was the sole inheritor of a site with 1000's of access violations per day! I didn't take the one way ticket to Brazil and the perserverance has paid off. For those who're interested, here was the cause and solution. This may be of help to those who use "Screen.OnActiveControlChange := MyProcedure;"
The access violations were limited to one monolethic application which is used for maintaining policies. The main form for this app uses Screen.OnActiveControlChange in order to keep tabs on the prior control. Where it came unglued, was that one of the many subforms (a product form), also uses this command with its own procedure to be called when there is a control change on that form. Now for what was happening. If a user went from the mainform, into this particular product form and out again to the main form, the last "Screen.OnActiveControl := MyProductFormProcedure" that had executed while in the product form, was staying active. So when the user did something on the MainForm, or went into a different subform, then each time there was a change of active control, it would jump to the procedure in the product form! The product's form procedure for changes to the active control, was then trying to reference a grid which no longer existed, because the user was no longer in that form. Hence - access violation! Since dozens of users all use this app, all the time, and would often go into the product form, the result was 1000's of access violations per day! The simple solution was immediately on exit from the product form, back to the mainform, to re-state the command: "Screen.OnActiveControlChange := MyMainFormProcedure;". This way, the next time the control changed, it would correctly go back to calling MyMainFormProcedure, rather than MyProductFormProcedure in the product form. So that's a trap to be aware of when using OnActiveControlChange. It makes perfect sense, but it's easy to miss. Best Regards, Dave --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/