Solved

Program crashing on closing form/terminating

Posted on 2008-10-02
28
465 Views
Last Modified: 2012-05-05
Simplified this problem to the bare-bones, as follows:-

This program opens up an SQLConnection to a MySQL database, shows a form then does nothing.  When user closes the form, get error message as shown below.  Though I create the SQLConnection programmatically, I am putting other components on the form (SQLtable, Provider, CDS, DataSource).  


When run from IDE I get this message when closing the form:

Project ... faulted with message: 'system exception (code 0xc00000008) at 0x7c90e4df'.  Process stopped. ...

When run directly I get:

The instruction at 0x... reference memory at 0x....  The memory could not be read.

What am I doing wrong?
{some of this code was supplied by Geert Gruez in a Q I asked a while ago http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_23616528.html}
 

  private

    { Private declarations }

    fLibSysMySQLHandle: THandle;

  public

    { Public declarations }

    constructor Create(AOwner: TComponent); override;

    destructor Destroy; override;

  end;
 
 

constructor TForm2.Create(AOwner: TComponent);

var Err: DWord;

begin

  inherited Create(AOwner);

  fLibSysMySQLHandle := LoadLibrary('libmysql.dll');

  Err := GetLastError;

  if (fLibSysMySQLHandle = 0) and (Err > 0) then

    ShowMessage('Error ' + IntToStr(Err));

end;
 

destructor TForm2.Destroy;

begin

  if fLibSysMySQLHandle > 0 then

    FreeLibrary(fLibSysMySQLHandle);

  inherited Destroy;

end;
 
 
 
 

procedure TForm2.FormShow(Sender: TObject);

var

  username,password:string;

  sqlconnection:tsqlconnection;

begin

username:='user';

password:='userpass';

SQLConnection := TSQLConnection.Create(nil);

SQLConnection.DriverName := 'MySQL';

SQLConnection.LibraryName := 'dbexpmys30.dll';

SQLConnection.VendorLib := 'libmysql.dll';

SQLConnection.GetDriverFunc := 'getSQLDriverMYSQL';

SQLConnection.Params.Clear;

SQLConnection.Params.Add('DriverName=MySQL');

SQLConnection.Params.Add('HostName=bloggs.co.uk');

SQLConnection.Params.Add('Database=bloggs');

SQLConnection.Params.Add('User_Name='+username);

SQLConnection.Params.Add('Password='+password);

SQLConnection.Params.Add('BlobSize=1000');

SQLConnection.Params.Add('LocaleCode=0000');

SQLConnection.Params.Add('Compressed=False');

SQLConnection.Params.Add('Encrypted=False');

SQLConnection.Params.Values['FetchAll'] := 'True';

sqlconnection.loginprompt:=false;

SQLConnection.Open;

sqltable1.SQLConnection:=sqlconnection;
 

showmessage('hello world');
 

{I thought that maybe the problem was due to creating the SQLConnection, but not properly destroying it afterwards, so I put this lot in}
 

sqltable1.SQLConnection:=nil;

sqlconnection.Close;

sqlconnection.Free;

sqlconnection:=nil;

end;

Open in new window

0
Comment
Question by:moorhouselondon
  • 16
  • 8
  • 2
  • +1
28 Comments
 
LVL 14

Expert Comment

by:SteveBay
ID: 22628248
Sounds like a misbehaving component to me.  I would try selectively removing components one at time to see if you can isolate the offender.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 22628254
there's nothing wrong with this code, is that all or it is a part of bigger project?

anyway, when program crashes when run from IDE stop it and take a look at call stack.

ziolko.
0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22628338
It has been cut-down from a utility I am writing which has some Indy components on it (IdMessage, IdPop3 and IdAntifreeze).  I have knocked out all code to do with Indy, but the components are still on the form.

btw, this is in Delphi 2007.
0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22628363
:7c90e4df ntdll.KiRaiseUserExceptionDispatcher + 0x37
:7c90e4f4 ntdll.KiFastSystemCallRet
:00d4cbfe ; C:\WINDOWS\system32\libmySQL.dll
:7c90118a ntdll.LdrInitializeThunk + 0x24
:7c923aba ; ntdll.dll
:7c81ca96 ; C:\WINDOWS\system32\kernel32.dll
:7c81cb0e kernel32.ExitProcess + 0x14
:00405229 @Halt0 + $C5



This is the Call Stack after crash.  I have no idea how to interpret this!
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 22628395
>> I have knocked out all code to do with Indy, but the components are still on the form.
Just because there is no code assicated with components does not mean that they will not execute OnCreate and OnDestroy methods
0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22628557
I have removed all Indy components, and replaced the procedure call (line 60 of the program listing in my Q - replaced with showmessage).  This is what I have at the top of the program:-

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdMessage, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase,
  IdMessageClient, IdPOP3, ExtCtrls, ComCtrls, WideStrings, FMTBcd, DBClient,
  DB, SqlExpr, Provider,idattachmentfile,idattachmentmemory,idtext;

type
  TForm2 = class(TForm)
    DataSource1: TDataSource;
    DataSetProvider1: TDataSetProvider;
    SQLTable1: TSQLTable;
    ClientDataSet1: TClientDataSet;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    lvheaders: TListView;
    TabSheet3: TTabSheet;
    lvmessageparts: TListView;
    TabSheet4: TTabSheet;
    Memo1: TMemo;
    procedure FormShow(Sender: TObject);


Do you think I need to remove the unused "uses" entries?  As you can see, I am using pagecontrol, tabsheets and listviews - are these likely to harbour any problem?
0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22628581
Sorry, I should have said "I have now removed all Indy components, as per your suggestion..."  Problem is still occurring.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 22628594
my bet is on this DLL maybe there's some thread running in background that is not terminated properly, try removing code that loads/calls/releases library and see if error is still there

ziolko.
0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22628647
If the code in #22628557 is spliced to the code in the Q itself, that is now the complete program!
0
 
LVL 21

Expert Comment

by:ziolko
ID: 22628775
>>Do you think I need to remove the unused "uses" entries?
yes.

also comment-out code loading DLL, call stack indicates that there's problem.

ziolko.
0
 
LVL 6

Expert Comment

by:JosephGlosz
ID: 22628804
would you try one simple thing: put in a sleep(5000) right after the FreeLibrary call?
0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22628846
I'm calling it a night.  I have meetings to attend tomorrow but will be back here early evening (GMT).

0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22628859
Just seen your comment Joseph... will try that right now...
0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22628879
...and ziolko's too...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 31

Author Comment

by:moorhouselondon
ID: 22629010
Put the sleep in, it paused, then crashed
Took out the load library, still no go
Took out most things from uses, still crashing on exit.
0
 
LVL 6

Expert Comment

by:JosephGlosz
ID: 22629034
the reason for the sleep is to give the DLL time to unload properly. I have a DLL that uses RIO that needs exactly that because of "lazy" or delayed cleanup when it is unloading. Without that sleep, my main program has a crash similar to yours.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 22629060
can you post here complete .pas and .dfm of this form?

ziolko.
0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22629132
Here's the pas (dfm will follow shortly)

unit Unit2;
 

interface
 

uses

  Windows, Messages, SysUtils, {Variants,} Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, {FMTBcd,} DBClient, DB, SqlExpr, Provider, ComCtrls, FMTBcd {FMTBcd{, IdMessage, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent,

  IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase,

  IdMessageClient, IdPOP3, ExtCtrls, ComCtrls, WideStrings, FMTBcd, DBClient,

  DB, SqlExpr, Provider,idattachmentfile,idattachmentmemory,idtext};
 

type

  TForm2 = class(TForm)

    DataSource1: TDataSource;

    DataSetProvider1: TDataSetProvider;

    SQLTable1: TSQLTable;

    ClientDataSet1: TClientDataSet;

    PageControl1: TPageControl;

    TabSheet1: TTabSheet;

    TabSheet2: TTabSheet;

    TabSheet3: TTabSheet;

    TabSheet4: TTabSheet;

    procedure FormShow(Sender: TObject);

  private

    { Private declarations }

    fLibSysMySQLHandle: THandle;

  public

    { Public declarations }

    constructor Create(AOwner: TComponent); override;

    destructor Destroy; override;

  end;
 

var

  Form2: TForm2;
 

implementation
 

{$R *.dfm}

var

  fname,shortdesc,longdesc:string;

  intindex:integer;
 
 
 
 
 

constructor TForm2.Create(AOwner: TComponent);

var Err: DWord;

begin

  inherited Create(AOwner);

{  fLibSysMySQLHandle := LoadLibrary('libmysql.dll');}

  Err := GetLastError;

  if (fLibSysMySQLHandle = 0) and (Err > 0) then

    ShowMessage('Error ' + IntToStr(Err));

end;
 

destructor TForm2.Destroy;

begin

  if fLibSysMySQLHandle > 0 then

{    FreeLibrary(fLibSysMySQLHandle);}

  inherited Destroy;

end;
 
 
 

procedure TForm2.FormShow(Sender: TObject);

var

  nextid,nextmessage:integer;

  username,password:string;

  sqlconnection:tsqlconnection;

begin

nextid:=0;

username:='user';

password:='userpass';

SQLConnection := TSQLConnection.Create(nil);

SQLConnection.DriverName := 'MySQL';

SQLConnection.LibraryName := 'dbexpmys30.dll';

SQLConnection.VendorLib := 'libmysql.dll';

SQLConnection.GetDriverFunc := 'getSQLDriverMYSQL';

SQLConnection.Params.Clear;

SQLConnection.Params.Add('DriverName=MySQL');

SQLConnection.Params.Add('HostName=bloggs.co.uk');

SQLConnection.Params.Add('Database=bloggs');

SQLConnection.Params.Add('User_Name='+username);

SQLConnection.Params.Add('Password='+password);

SQLConnection.Params.Add('BlobSize=1000');

SQLConnection.Params.Add('LocaleCode=0000');

SQLConnection.Params.Add('Compressed=False');

SQLConnection.Params.Add('Encrypted=False');

SQLConnection.Params.Values['FetchAll'] := 'True';

sqlconnection.loginprompt:=false;

SQLConnection.Open;

sqltable1.SQLConnection:=sqlconnection;

sqltable1.SQLConnection:=nil;

sqlconnection.Close;

sqlconnection.Free;

sqlconnection:=nil;

end;
 

end.

Open in new window

0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22629157
Here's dfm

btw in case you were wondering, there is no Tform1.

object Form2: TForm2

  Left = 0

  Top = 0

  Caption = 'Form2'

  ClientHeight = 387

  ClientWidth = 508

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'Tahoma'

  Font.Style = []

  OldCreateOrder = False

  OnShow = FormShow

  PixelsPerInch = 96

  TextHeight = 13

  object PageControl1: TPageControl

    Left = 0

    Top = 0

    Width = 508

    Height = 387

    ActivePage = TabSheet4

    Align = alClient

    TabOrder = 0

    object TabSheet1: TTabSheet

      Caption = 'POP Account Detail'

    end

    object TabSheet2: TTabSheet

      Caption = 'Message Headers'

      ImageIndex = 1

    end

    object TabSheet3: TTabSheet

      Caption = 'Attachment List'

      ImageIndex = 2

    end

    object TabSheet4: TTabSheet

      Caption = 'Long Description'

      ImageIndex = 3

    end

  end

  object DataSource1: TDataSource

    Left = 256

    Top = 256

  end

  object DataSetProvider1: TDataSetProvider

    Left = 176

    Top = 256

  end

  object SQLTable1: TSQLTable

    Left = 112

    Top = 256

  end

  object ClientDataSet1: TClientDataSet

    Aggregates = <>

    Params = <>

    Left = 216

    Top = 256

  end

end

Open in new window

0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22629217
If this is problem is due to a subtle difference in Library versions, how can I ensure I have the correct versions?  Searching on the internet there seems to be some controversy over what works and what doesn't.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 22629223
as I expected, no problem for me.
this form is just shown and nothing more?
do you have any other references to this dll?

ziolko.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 22629305
..of course I don't have database so I skipped SQLConnection.Open; but everything else works, even loading DLL.

ziolko.
0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22629337
I have nothing else using this dll.

A bit of history:-

I had some programs using MySQL successfully.  Hard drive caved in.  Installed new hard drive.  Installed Delphi from scratch (no mean feat, I bought it as a download from Codegear's site).  Had problems modifying existing MySQL programs, runtime errors.  Fiddled around with library statements to get to the assignments shown above, plus the problem which Geert Gruez solved (see my previous Q).  This works but I get this crash when terminating the program.
0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22629361
It sounds like this is a DLL version problem if you (ziolko) ran the program cleanly.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 22629386
huh strange, there's always brutal method - remove this form from project create new empty one and start adding components one-by-one starting with standard ones.

I'm heading to bed now.. maybe something will popup in my head untill tomorrow morning:)

ziolko.
0
 
LVL 31

Author Comment

by:moorhouselondon
ID: 22629390
Off to bed now... feeling verrrry slleeeeepy zzzzz

Will be back tomorrow.  I think progress has been made.... Thanks for everyone's input so far....
0
 
LVL 21

Accepted Solution

by:
ziolko earned 500 total points
ID: 22631863
you said that you've reinstalled your machine, and have new Delphi, is it different version than previous one?

anyway for version sake, I used dll downloaded from this location:
http://www.dll-files.com/dllindex/dll-files.shtml?libmysql

ziolko.
0
 
LVL 31

Author Closing Comment

by:moorhouselondon
ID: 31502551
Ziolko's hit the jackpot!  

22.10.06 1,519,616 bytes : file downloaded from ziolko's link
25.10.06 2,031,616 bytes : file I was using

Thanks to all who contributed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

22 Experts available now in Live!

Get 1:1 Help Now