我在Dll中加载了一个窗体,然后在主应用程序中调用Dll中显示窗体的函数,将dll中的窗体显示出来,操作完成后关掉这个dll窗体,当再次在主应用程序中调用这个显示窗体的函数时,dll窗体只是闪了一下,并没有显示到屏幕上。请问这是怎么回事!?!?!
我写的显示dll窗体的函数是:
procedure ShowForm(hdl:THandle);stdcall;
begin
Application.Handle:=hdl;
frmLogin:=TfrmLogin.Create(Application);
try
 frmlogin.ShowModal;
finally
 frmlogin.Free;
end;
end;

解决方案 »

  1.   

    没看明白 既然已经ShowModal了为啥还要Free掉呢 
    看看别人的说法吧
      

  2.   

    是这样的,dll中的窗体是完成一个单据录入的操作的,单据录入完成后就需要关掉这个窗体,当有新的单据需要录入时还要打开。
    所以需要反复的关掉,打开。
      

  3.   

    procedure ShowForm(hdl:TApplication);stdcall;
    beginfrmLogin:=TfrmLogin.Create(hdl);
    try
     frmlogin.ShowModal;
    finally
     frmlogin.Free;
    end;
    end;
    调动:
      ShowForm(Application);试试。
      
      

  4.   

    Function OpenAM_Car(Handle_car:THandle):Longint;
    var
    i:integer;
    begin
      Result:=-1;
      if Not Assigned(car_f) then
      begin
      try
       Application.Handle:=Handle_car;
       car_f.WindowState:=wsMaximized;
       //Windows.SetParent(car_f.Handle,Parent.Handle);
       car_f.Show;
       Result:=Longint(car_f);
       except
       end;
      end
       else
       begin
       if car_f.WindowState=wsMinimized then
       car_f.WindowState:=wsMaximized
       else
       car_f.Show;
       end;end;exports
      OpenAM_Car;begin
    end.
      

  5.   

    我将我的代码贴出来看能不能帮你啰,我dll的也是完成独立的数据录入功能:DLL 工程文件:
    library feemod;uses
      SysUtils,
      fee in 'fee.pas' {FeeForm};{$R *.res}exports
      ShowFeeFrm;begin
    end.
     
    =====================DLL 窗体文件:unit fee;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Controls, Forms,
      Dialogs, ExtCtrls, ActiveX, StdCtrls, ADODB, DB;type
      TFeeForm = class(TForm)
        Form1: TForm;
        ADOConnection1: TADOConnection;
        Query1: TADOQuery;
        Table1: TADOTable;
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Label4: TLabel;
        Label5: TLabel;
        ContentEdit: TEdit;
        MonEdit: TEdit;
        DatePicker: TDateTimePicker;
        PayMethodCombo: TComboBox;
        DepartmentCombo: TComboBox;
        Button1: TButton;
        Button2: TButton;
        function CheckNum:boolean;
        function CheckInput:boolean;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;{
    注意这里!!
    var
      FeeForm: TFeeForm;
    上面两行注释掉了,在ShowFeeFrm过程里面定义
    }
    procedure ShowFeeFrm(Hwd,HIcon:THandle);stdcall;
    implementation{$R *.dfm}procedure ShowFeeFrm(Hwd,HIcon:THandle);
    var
      FeeForm: TFeeForm; //改在这里定义了!
    begin
      Application.Handle:=Hwd;
      Application.Icon.Handle:=HIcon;
      FeeForm:=TFeeForm.Create(Application);
      FeeForm.ShowModal;
      FeeForm.Free;
    end;procedure TFeeForm.Button1Click(Sender: TObject);
    var
      SqlStr:string;
    begin
    if CheckNum and CheckInput then
      begin
        SqlStr:='Sql语句';
        Query1.Close;
        Query1.SQL.Clear;
        Query1.SQL.Add(SqlStr);
        try
          Query1.ExecSQL;
          Showmessage('数据保存成功!');
        except
          Showmessage('数据保存出错!');
        end;
      end;
    end;procedure TFeeForm.Button2Click(Sender: TObject);
    begin
    close;
    end;{
    注意如果使用的是ADO数据控件,要加上以下几行 !!!!
    切记引用 ActiveX 单元!
    }
    initialization
        CoInitialize(nil);
    finalization
        CoUninitialize;end.====================调用窗体代码:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;procedure ShowFeeFrm(Hwd,HIcon:THandle);stdcall;external 'feemod.dll';
    implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowFeeFrm(Applicatioin.Handle,Application.Icon.Handle);
    end;end.
    ======================我的代码在 DELPHI 7+ACCESS2000+WIN2003 运行正常