DLL + Form & TMS

Hi, can someone help me? :)



I'm using Delphi2010 & windows 7.



The problem is:

I want to create DLL that exports function showing form with
AdvStringGrid. So my host application loads this DLL, calls function and
releases the library. After that I get AV. If I show form without
AdvStringGrid, i had no problem.



Steps to reproduce:

  1. run Delphi, create 2 projects : VCL Application (testApp.exe) & DLL Library (test.dll);
  2. Add procedure to dll:
    procedure ShowForm();   stdcall;

    var f : TForm;

    begin

        f := TForm.Create(nil);

        f.ShowModal();

        f.Free;

    end;

exports

    ShowForm;


we have to add Forms unit to uses section;

3. next step: loading library in host application:

add the TButton and ButtonClick event like this:

procedure TForm1.Button1Click(Sender: TObject);

type TShowFormProc = procedure; stdcall;

var libHandle : THandle;

    showForm : TShowFormProc;

begin

    libHandle := LoadLibrary('test.dll');

    @ShowForm := GetProcAddress(libHandle, 'ShowForm') ;

    ShowForm();

    freeLibrary(libHandle);

end;



so, all work fine, without any problems.

But I want to use AdvancedStringGrid in my library. so I add AdvGrid unit. I don't have to do something else. After including AdvGrid I have AV  in ButtonClick event.

Seems there is problem in initialization & finalization part of these units, so can someone tell me: how to use TMS Components in DLLs?

Don't think that it is specific problem of TMS Grid, so I've posted this message in "General"  section.

Thanks,
Terekhov Andrew,
Petrozavodsk State University
teran (at) psu.karelia.ru

I cannot see a problem here using TAdvStringGrid from a DLL.
Sample project can be downloaded from:

http://www.tmssoftware.net/public/ProjectGroup1.zip 

thanks for sample:) seems I have problems somewhere else.

strange, now my example works fine. magic :)

still can't solve my problem :)

1. I have DLL without any code, it only contains one empty form TTestForm
2. Host application (test.exe) that loads this DLL at startup and releases in the end

If I add AdvGrid unit in TTestForm "uses" section, i will get AV-error.

don't understand what is wrong.

here is my source code: http://disk.karelia.ru/fast/cr4emR8/test.zip


can you explain me the next thing?:
In sample project there is function FormManageCall : it is called in button1click event and shows form with grid from DLL. So it loads DLL using LoadLibrary() and stores DLL handle in the local variable aHandle.

In FormClose event we use method CloseAllForm() wich calls the same-name function from library; But here again we are loading library. why?
we have to load library only once at the startup. Using 2 calls to LoadLibrary we have to "references" to library, so we have to call FreeLibrary() two times, but there is only one FreeLibrary-call.

so if you define global aHandle, and delete "aHandle := LoadLibrary('TestDll.DLL');" line from CloseAllForm method, then you will get the same AV-error as I have.