Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datamodule Destruction - Access Violation

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I've found a hiccup in my code. I'm using Delphi 5 against an SQL server 7.0 database. Sometimes when I close my application it terminates successfully - in other instances it causes an 'Access Violation' on the 'end;' of the datamodule 'OnDestroy' event (if I've used a different set of queries in the datamodule). Someone suggested that this might be down to another of the 'live' forms still accessing the components in the datamodule - is there any way I can track this ? As far as I'm aware the forms + datamodules are created and destroyed in the correct order, the datamodule being the second from last thing being destroyed (main form being last with no obvious links to the datamodule in question). Can anyone give me any pointers with this ?
Thanks in advance,
Steve.
 
Steve,

Not entirely certain, but if you're creating and destroying the dataModule yourself, make certain you destroy it be calling its free method, not release.

For example, don't do this:

Code:
with tDataModule1.create( application ) do
try
   doSomething()
finally
   release;
end;

Why? Because tDatamodules descend from tComponent, not tCustomForm. Ergo, the release method that gets executed is the one for the form running the code, leading to varying instabilities.

Can't you try to determine where the AV's are occurring? Don't forget that you can use the Call Stack when Delphi first catches your AV when you run the program through the IDE.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top