写这个小程序的时候没有想过用DLL(最后还是用了动态调用DLL的窗体),程序有十个个窗体.
问题:运行程序-仓库管理下的"收料"(调用DLL窗体,反复开启关闭没问题).关闭后运行基体资料下的"常用人员"(是这种普通调用窗体的方式:form1.windowstate:=wsminimized;
                          form10.SHOW;还有很多都是用的这种方式),运行正常.现在再反过来运行仓库管理下的"收料"(动态调用DLL窗体)时就报错"project vertex_erp.exe raised exception class eaccessviolation with message'access violation at address 000000048.read of address 000000048'.process stopped.use step or run to continue"所以我想问题是不是出在调用这里.DLL调用代码:
unit Unit6;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls, Buttons;type
  TFrame6 = class(TFrame)
    Label2: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure FrameExit(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
 formref:longint;
 function myshowform1(ahandle:thandle):longint;stdcall;
 procedure mycloseform1(aformref:longint);stdcall;
implementation
function myshowform1;external 'dll_1.dll';
procedure mycloseform1;external 'dll_1.dll';{$R *.dfm}procedure TFrame6.BitBtn1Click(Sender: TObject);
begin
IF formref<>0 then
  begin
   mycloseform1(formref);
   formref:=myshowform1(application.Handle);
  end
else
  begin
   formref:=myshowform1(application.Handle);
  end;
end;procedure TFrame6.FrameExit(Sender: TObject);
begin
mycloseform1(formref);
end;end.普通窗体的调用代码:
uses Unit10, Unit1, Unit11, Unit12, Unit13, Unit14, Unit15, Unit16, Unit17,
  Unit18, Unit19, Unit20, Unit22, Unit23, Unit24;{$R *.dfm}procedure TFrame9.BitBtn1Click(Sender: TObject);
var
form10:tform10;
begin
form10:=tform10.Create(nil);
form10.ShowModal;
end;

解决方案 »

  1.   

    procedure TFrame6.BitBtn1Click(Sender: TObject); 
    begin 
    IF formref <>0 then 
      begin 
      mycloseform1(formref); 
      formref:=myshowform1(application.Handle); //报错时就停在这里了.
      

  2.   


    procedure TForm1.Button1Click(Sender: TObject);
    var
      Handles  :THandle;
      ShowDLLFrom :TShowDLLFrom;
    begin 
     try
        Handles  :=LoadLibrary('XXX.dll');
        if Handles  <>0 then
          @ShowDLLFrom :=GetProcAddress(Handles ,'ShowDLLFrom');
        if @ShowDLLFrom <>Nil then
          ShowDLLFrom(Handle);
      finally
        FreeLibrary(Handles);
      end;
    end;//Dll中的ShowDLLFrom
    function ShowDLLFrom(AHandle: THandle):Boolean;
    var
      AboutForm : TForm1 ;
    begin
      Application.Handle :=AHandle;
      AboutForm := TForm1.Create(Application);
      AboutForm.ShowModal;
      AboutForm.Free;
    end;