大家好,帮忙看一下,下面的代码出现一个问题,就是调用继承过来的表单后,引用dll,表单是能够打开的,并且在该表单中写的代码也是能够运行正常,但有些按钮继承的是父类中的代码,在这边就运行不了,并会造成程序死在那边动弹不得,因为是刚学着做dll,可能代码写的有问题,希望大家帮忙看一下,谢谢!其中frmBom的继承关系是:tfrom->tfrmBase->tfrmInfoBase->tfrmBaseInfoBase->tfrmBaseDefine->tfrmbom
下面是原码:
library technics_dll;uses
  Forms,
  Windows,
  SysUtils,
  Messages,
  Dialogs,
  Classes,
  ActiveX,
  DataModule in 'public\DataModule.pas' {dmClient: TDataModule},
  Global in 'Public\Global.pas',
  Base in 'public\Base.pas' {frmBase},
  InfoBase in 'public\InfoBase.pas' {frmInfoBase},
  BaseInfoBase in 'public\BaseInfoBase.pas' {frmBaseInfoBase},
  BaseDefine in 'public\BaseDefine.pas' {frmBaseDefine},
  pasBom in 'order\pasBom.pas' {frmBom},
  pasBomcz in 'order\pasBomcz.pas' {frmBomcz},
  pasBomdc in 'order\pasBomdc.pas' {frmBomdc},
  pasBomzx in 'order\pasBomzx.pas' {frmBomzx};procedure techImport(psconn:pchar;sequ : Integer);stdcall;
begin
  if not FileExists('public_dbcon.udl') and (psconn='')  then
  begin
      messagebox(0,'数据库配置文件 pic.udl 不存在','错误',16);
      exit;
  end;
   dmClient:=TdmClient.Create(dmClient);
   dmClient.adocnequip_manage.Connected:=False;
   dmClient.adocnequip_manage.ConnectionString:=psconn;
   dmClient.adocnequip_manage.Connected:=True;
   if sequ=1 then
   begin
      frmBom:=TfrmBom.Create(frmbom);
      frmBom.ShowModal;
   end;   if sequ=2 then
   begin
      frmBomcz:=TfrmBomcz.Create(frmBomcz);
      frmBomcz.ShowModal;
   end;   if sequ=3 then
   begin
      frmBomdc:=TfrmBomdc.Create(frmBomdc);
      frmBomdc.ShowModal;
   end;   if sequ=4 then
   begin
      frmBomzx:=TfrmBomzx.Create(frmBomzx);
      frmBomzx.ShowModal;
   end;
end;
{$R *.res}
exports
  techImport;
begin
end.

解决方案 »

  1.   

    我想你沒搞請清楚構造函數create的參數的含義!你把參數改為appliaction,這意味著此form的生存周期由appliaciton控制
      

  2.   

    Avan_Lau,你好,那我这个代码应该怎么改?
      

  3.   

    1、 if sequ=1 then 
      begin 
          frmBom:=TfrmBom.Create(frmbom); //樂觀情況下,frmbom為nil,否則不堪設想。建議傳application
          frmBom.ShowModal; 
      end;   if sequ=2 then 
      begin 
          frmBomcz:=TfrmBomcz.Create(frmBomcz); //同上
          frmBomcz.ShowModal; 
      end;   if sequ=3 then 
      begin 
          frmBomdc:=TfrmBomdc.Create(frmBomdc); //同上
          frmBomdc.ShowModal; 
      end;   if sequ=4 then 
      begin 
          frmBomzx:=TfrmBomzx.Create(frmBomzx); //同上
          frmBomzx.ShowModal; 
      end; 
    2、
    1)、以下代碼寫在dll工程文件裡 
    procedure  DLLEntryPoint(dwReason:  DWord); 
    begin 
        case  dwReason  of 
            DLL_PROCESS_ATTACH:;//在這裡記錄原來的application 
            DLL_PROCESS_DETACH:;//在這裡還原原來的application  
            DLL_THREAD_ATTACH:  ; 
            DLL_THREAD_DETACH:  ;  
        end; 
    end; begin //以下兩行寫在dll工程文件自帶的begin..end 
        DllProc  :=@DLLEntryPoint; 
        DLLEntryPoint(DLL_PROCESS_ATTACH); 
    end. 
    2)、你在調用函數時有傳application,這時你把dll的application的handle換成傳進來的那個application的handle
      

  4.   

    Avan_Lau,你好,不好意思,你说的"你在調用函數時有傳application,這時你把dll的application的handle換成傳進來的那個application的handle",我不太明白,这个要在哪里改啊?麻烦你再指导一下,谢谢!
      

  5.   

    上面已說明,這里改
    2、 
    1)、以下代碼寫在dll工程文件裡 
    procedure  DLLEntryPoint(dwReason:  DWord); 
    begin 
        case  dwReason  of 
            DLL_PROCESS_ATTACH:;//在這裡記錄原來的application 
            DLL_PROCESS_DETACH:;//在這裡還原原來的application  
            DLL_THREAD_ATTACH:  ; 
            DLL_THREAD_DETACH:  ;  
        end; 
    end;