Connection-DLL

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
thias
Posts: 2
Joined: Wed 10 Aug 2005 05:08

Connection-DLL

Post by thias » Wed 10 Aug 2005 05:16

Hi,
i tried the demo (dll) and it works fine. but i need a modal dialog - so i altered the code (showModal). and it still works. now i want to load the libray, show the dialog and afterwards unload the library - all in one procedure. i alway get the same errors: "too many consecutive exceptions". the code is simple:

Code: Select all

var
    AssignMyConnection: TAssignMyConnection;
    ShowForm        : TShowForm;
    HideForms       : THideForms;
    hDLL            : hmodule;
begin

    hDLL := LoadLibrary('My_DLL.dll');
    if hDLL  0 then
        begin
            @AssignMyConnection := GetProcAddress(hDLL, 'AssignConnection');
            if @AssignMyConnection  nil then
                AssignMyConnection(MyConnection);
        end
    else
        MessageDlg('Cannot load DLL', mtError, [mbOk], 0);

    if hDLL  0 then
        begin
            @ShowForm := GetProcAddress(hDLL, 'ShowForm');
            if @ShowForm  nil then
                ShowForm; // modal!
        end;
    if hDLL  0 then
        begin
            @HideForms := GetProcAddress(hDLL, 'HideForms');
            if @HideForms  nil then
                HideForms;
        end;
    if hDLL  0 then
        begin
            FreeLibrary(hDLL); // exceptions!!
        end;
i use version 4.0
the dll ist the same as in the demo (except that the form is modal)
what can i do? any ideas?
thanks in advance
matthias

Paul
Posts: 725
Joined: Thu 28 Oct 2004 14:06

Post by Paul » Wed 10 Aug 2005 08:25

We cannot reproduce your problem in our environment (Delphi 7.0, MyDAC 4.00.0.2 Trial or Standard). I put your code to Button1Click event of new button in ExeMain, changed "Show" to "ShowModal". Than I click Button1.
Your code is correct. Can you reproduce this problem if you click 1. Load DLL,2. Show Form,3. Hide Forms,4. Free DLL in your application?

thias
Posts: 2
Joined: Wed 10 Aug 2005 05:08

Connection-DLL

Post by thias » Wed 10 Aug 2005 08:40

Thank your for your fast reply
I use D7-Enterprise and the latest MyDAC 4 Standard

The dll ist the same as in the demo (except the ShowModal)
I changed the code now but the error ist still there

first of all i defined hdll global. here is the code:

Code: Select all

type
    TForm1 = class(TForm)
        MyConnection: TMyConnection;
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;  
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
    private
        { Private declarations }
    public
        { Public declarations }
    end;
    TAssignMyConnection = procedure(MyConnection: TMyConnection); cdecl;
    TShowForm = procedure; cdecl;
    THideForms = procedure; cdecl;
var
    Form1           : TForm1;
    hDLL            : hmodule;
implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
var
    AssignMyConnection: TAssignMyConnection;
begin
    hDLL := LoadLibrary('My_DLL.dll');
    if hDLL  0 then
        begin
            @AssignMyConnection := GetProcAddress(hDLL, 'AssignConnection');
            if @AssignMyConnection  nil then
                AssignMyConnection(MyConnection);
        end
    else
        MessageDlg('Cannot load DLL', mtError, [mbOk], 0);

end;

procedure TForm1.Button2Click(Sender: TObject);
var
    ShowForm        : TShowForm;
    HideForms       : THideForms;
begin
    if hDLL  0 then
        begin
            @ShowForm := GetProcAddress(hDLL, 'ShowForm');
            if @ShowForm  nil then
                ShowForm;
        end;
    // Modal---> need to be closed after showing
    if hDLL  0 then
        begin
            @HideForms := GetProcAddress(hDLL, 'HideForms');
            if @HideForms  nil then
                HideForms;
        end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
    if hDLL  0 then
        begin
            FreeLibrary(hDLL);
        end;
end;
I get the error after clicking button4 :(

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Mon 22 Aug 2005 14:42

Please send us (mydac*crlab*com) complete small sample

Post Reply