Steps to destroy doa objects

Equinox

Member²
Hello,

in my application I have the problem that I always get an access violation when the program is closed by the user. After a long search I traced down the source of the problem to a TOracleSession object. As soon as I established a connection by setting Session.Connected := true - the problem will occur when the application is closed. If I do not connect the session, I get no problem.

I've now tried various things like setting Session.Connected := false or calling Close on all Datasets involved before calling the final Destroy of the class which holds the DOA objects but nothing seems to work.

So what is the exact proper way to destroy the doa objects ?

I'm using DOA objects 4.0.7.1 in combination with Delphi7

Thanks...
 
Additional info : In the debugger I see the exception is being triggered in System.pas in the Method

procedure TObject.Free;
begin
if Self nil then
Destroy;
end;

The error message says there were too many exceptions of type access violation to continue.
 
You should not need to destroy these objects (unless you create them dynamically with no owner).

Access Violations are notorious for giving misleading error reasons.
They do not show up when the problem is created, they only show up when the violation is triggered.

Scour your code for some object that you are trying to access AFTER it has been freed.

For example (somewhat contrary to what I said above) if you free the datamodule on which your session is located and then try to access the session you will get an access violation.

Is the dataModule (and session) actually created if you do not connect?

Basically, it is not the way one frees an OracleSession object that is your problem, it is most likely that you are trying to access it (or something else) after it has already been destroyed.
 
I know about that and double checked everything without success. The only thing I found is that the exception won't be thrown unless I called this method once during the lifetime of the application :

procedure TOracle_Interface.Init();
begin
try
mSession.Connected := False;
mSession.LogonDatabase := mDatabase;
mSession.LogonPassword := mPassword;
mSession.LogonUsername := mUser;
mSession.Connected := True;

Login();
except
on E: Exception do
begin
mSession.Connected := False; //cancel connection attempt
if Assigned(OnStatusMessage) then
OnStatusMessage('Database Connection FAILED : ' + E.Message);
end;
end;
end;

TOracleInterface is the the DataModule derivation which holds the Session object as well as the Datapackages, Datasets aso.
At runtime, I can call the method and it works with no problems, but when I close application I get the AV. If I never call this method, there is no AV when I close application.

So where is the explaination for this ? I tried everything I can think of, manually destroying / freeing all doa objects in destructor, not defining a destructor at all - nothing makes a difference.
 
Now I removed everything from the destructors and got this situation:

ActiveX creates Datamodule (mDBMod)
mDBMod := TOracle_Interface.Create(self, User, Password, Database);

The constructor saves User Password and Database and calls Init() from the last post.

No extra destructor is defined in the Datamodule and I don't call the default destructor from the activeX.

When I close the application, I still get the AV.

Then I have a override Create which doesn't call Init(). If I call that one instead and close application, no AV
 
I do not know how the ActiveX became involved and it makes me curious about your name TOracle_Interface.

Is it possible that you have an interfaced object somewhere in this ownership hierarchy that is reference counting and is trying to free the session during the process of destroying itself after it has already been freed by Delphi?

Also curious about having
mSession.Connected := True;
Login();

If mSession.Connected := True; succeeds you are logged in.

Clive
 
The ActiveX is the application I am developing. It has to be embedded into a customer application. What is wrong about the name ?

I don't have any interfaced objects, just an activeX project with a couple of frames and the datamodule.

About the Login(), that method just calls a cerain stored procedure in the database and has no importance for my problem.

I'm thinking about using ADO instead of the DOA objects now, because after a week there is still no solution or explaination for this and it really stops me from finishing the project.
 
Back
Top