Delphi: access violation after dll call procedure

I created a procedure in dll that opens a form and then prints a report. This procedure works great with exe. I wrapped the block that contains this procedure and forms it in the dll, and exported the following procedure:

{$R *.res}


Procedure PrintTopSellers; stdcall;
begin
  Form1 := TForm1.create(nil);
  GetMonth := TGetMonth.create(nil);
  Form1.PrintTopSellers;
end;


exports PrintTopSellers;

begin
end.

Now I call this PrintTopSellers procedure from exe as follows:

procedure TForm1.Button5Click(Sender: TObject);
type
  TRead_iButton = function :integer;
var
    DLL_Handle: THandle;
    Read_iButton: TRead_iButton;
Begin
    DLL_Handle := LoadLibrary('c:\Catalog.dll');
    if DLL_Handle <> 0 then
    begin
       @Read_iButton:= GetProcAddress(DLL_Handle, 'PrintTopSellers');
        Read_iButton;
    end;
    application.ProcessMessages;
    FreeLibrary(DLL_Handle);

end;

The procedure call works fine. However, after closing the calling exe, I get an access violation - "Access violation at address 00BAC89C. Reading address 00BAC89C."

Appreciate any help. I am using Delphi 7. Thanks

+5
source share
2 answers

DLL Form1, . . DLL, , , DLL. , , , .

, , DLL. , , , PrintTopSellers .

Procedure PrintTopSellers; stdcall;
begin
  Form1 := TForm1.create(nil);
  try
    GetMonth := TGetMonth.create(nil);
    try
      Form1.PrintTopSellers;
    finally
      GetMonth.Free;
    end;
  finally
    Form1.Free;
  end;
end;

, DLL, TRead_iButton .

TRead_iButton = procedure; stdcall;

, .

+6

"TRead_iButton = function: integer; register;"

" PrintTopSellers; stdcall;"

/, ?

. ditch DLL (BPL),


Form1.PrintTopSellers, TGetMonth. exe, DLL.


, AV - . Debug info + , Jedi CodeLibrary ( Delphi IDE) madExcept, EurekaLog, .

Delphi Win32


DLL EXE Runtime?

+3

All Articles