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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange error with ODBC

Status
Not open for further replies.

Jonah86

Programmer
Dec 11, 2003
152
US
Hello. I posted this problem in the ODBC board as well...but I figured maybe someone here has encountered this before, so maybe they can help.

**copied from the ODBC board**
I have an app I made with delphi that accesses a MySQL database, I have an ODBC connection set up for this purpose. Now, sometimes when I close the Delphi app it gives me this error: "Exception EAccessViolation in module IDODBC32.DLL" and references some memory addresses. Now this happens on any computer I run the app on, and only happens sometimes. It's completely random in appreance, when this error occurs. I can't even begin to imagine what could be causing this.

Any suggestions would be greatly appreciated.

**End ODBC post**

The thing is, it only happens when I go to close the app, after I hit Exit. It happens on ANY form, and after seemingly ANY possible combination of actions within the app. It just seems totally random. Aggrivating.
 
Is everything in your app being closed/freed properly?

Suggest creating an afterclose event for the TDatabase/TADOConnection or whatever you are using and see whether or not it triggers when you exit your app.

Good luck
Simon
 
What, exactly, is the best way to exit the program. I'm just using application.terminate at thie point in time, I'm not sure what else I should be doing to ensure that the application is closed/freed properly.

I'm using BDE, by the way. Connecting to MySQL, not sure if that makes a difference.

Thanks for your reply.
 
application.terminate is IMHO not a good to way to close your application. use the close method of your form.

what I always do is use the formcreate and formclose methods that belongs the main form. something like this :


procedure TFrm_main.InitApplication;

begin
AppClosing:=False;
LOpenChannels:=TStringList.Create;
Assert(LOpenChannels <> nil,'');
CreateChannelList;
end;


procedure TFrm_main.DestroyApplication;
begin
AppClosing:=True;
FreeAndNil(LOpenChannels);
WritePreferencesToRegistry(INT_PREF_MAIN); // save main preferences
end;

procedure TFrm_main.FormCreate(Sender: TObject);
begin
InitApplication;
end;


procedure TFrm_main.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DestroyApplication;
end;
 
I suspect that you use a TmainMenu with an exit option, and there are 2 ways to close your apllication:
1) with your exit option
2) Clicking the close icon on the form (A 3rd option is hitting the power button).

To synchronize the behaviour of the two methods:

procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if MessageDlg('Exit My Info System ?',
mtConfirmation, [mbYes, mbNo],0) = mrNo then
Canclose:= False;
end;
This is invoked by using the close icon on the main form X

Delphi take cares of all the clean-up stuff and this ishandled by the OnCloseQuery event

To make this code available to your exit button or menu item:

Drop a TActionList on your mainform, open the ActionList editor, add an action called MyClose

In the OnExecute event key in:

if CloseQuery then close;

I had similar experiences with access violations using the plain Close command in my exit menu item

Regards










Steven van Els
SAvanEls@cq-link.sr
 
whosrdaddy and Steven both offer valuable contributions. I offer this in addition.

I always have one autocreate form (the MainForm). Delphi will create and open that form. When you close it (Call Close method from button/menu or click close icon) Delphi closes the application in an orderly manner.

For all other forms either:
Make the owner the MainForm, they will then be freed in
an orderly manner before the MainForm is freed.
OR
Set the owner to nil on creation
Put Action:=caFree in the OnClose event
Make sure that the form is closed before closing the application.

You've got plenty of options now.
Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top