很奇怪的问题!在动态库里增加Form,里面有DBGRID,加载进来后,不能在DBGRID中用上下键移动,不响应任何键盘事件!!!

解决方案 »

  1.   

    把主程序的Application, Screen都传入到动态库中去试试.
      

  2.   

    能不能具体点?我前台程序只是个dll的函数调用,dll函数就是创建个Form,然后查询数据显示在DBGRID中。会是什么问题?请谈谈
      

  3.   

    这个问题,应该以前解决过,就是dll中输出的form,不能正确处理主程序的消息循环,你找下,
      

  4.   

    //测试代码,Dll//----------------MidForm.dpr
    library MidForm;uses
      SysUtils,
      Classes,
      Forms,
      Unit1 in 'Unit1.pas' {Form1};
    {$R *.res}
    exports
      CallModule;
    begin
    end.//----------------------Unit1.pas
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls;type
      TForm1 = class(TForm)
        DBGrid1: TDBGrid;
        DataSource1: TDataSource;
        ADOTable1: TADOTable;
        ComboBox1: TComboBox;
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormDestroy(Sender: TObject);
        procedure ComboBox1Change(Sender: TObject);
        procedure FormShow(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
    procedure CallModule(SS:TADOConnection);stdcall;
    implementation{$R *.dfm}
    var  Ado:TAdoconnection;
    procedure CallModule(SS:TADOConnection);stdcall;
    begin
      //Coinitialize(nil);
        Ado:=ss;
        if not Assigned(Form1) then
          Form1:=TForm1.Create(application);
    end;
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Action := caFree;
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      Form1 := nil;
    end;procedure TForm1.ComboBox1Change(Sender: TObject);
    begin
      Self.ADOTable1.Close;
      Self.ADOTable1.TableName:=ComboBox1.Text;
      Self.ADOTable1.Open;
    end;procedure TForm1.FormShow(Sender: TObject);
    begin
    if not Ado.Connected then  Ado.Open();
      Self.ADOTable1.Connection:=Ado;
      Ado.GetTableNames(Self.ComboBox1.Items,false);
    end;end.//----------------Unit1.dfmobject Form1: TForm1
      Left = 169
      Top = 189
      Width = 453
      Height = 263
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      FormStyle = fsMDIChild
      OldCreateOrder = False
      Position = poDefault
      Visible = True
      OnClose = FormClose
      OnDestroy = FormDestroy
      OnShow = FormShow
      PixelsPerInch = 96
      TextHeight = 13
      object DBGrid1: TDBGrid
        Left = 16
        Top = 64
        Width = 320
        Height = 120
        DataSource = DataSource1
        TabOrder = 0
        TitleFont.Charset = DEFAULT_CHARSET
        TitleFont.Color = clWindowText
        TitleFont.Height = -11
        TitleFont.Name = 'MS Sans Serif'
        TitleFont.Style = []
      end
      object ComboBox1: TComboBox
        Left = 16
        Top = 32
        Width = 145
        Height = 21
        Style = csDropDownList
        ItemHeight = 13
        TabOrder = 1
        OnChange = ComboBox1Change
      end
      object DataSource1: TDataSource
        DataSet = ADOTable1
        Left = 336
        Top = 24
      end
      object ADOTable1: TADOTable
        Left = 256
        Top = 24
      end
    end
      

  5.   

    arrii怎么就成了五星了, 哪来的???????????
      

  6.   

    //调用程序 exe//--------------Project2.dprprogram Project2;uses
      Forms,
      Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.
    //----------------Unit1.pasunit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus, DB, ADODB;type
      TForm1 = class(TForm)
        MainMenu1: TMainMenu;
        N1: TMenuItem;
        N2: TMenuItem;
        N3: TMenuItem;
        N4: TMenuItem;
        N5: TMenuItem;
        N6: TMenuItem;
        N7: TMenuItem;
        N11: TMenuItem;
        ADOConnection1: TADOConnection;
        procedure N3Click(Sender: TObject);
        procedure N4Click(Sender: TObject);
        procedure N6Click(Sender: TObject);
        procedure N2Click(Sender: TObject);
        procedure N11Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
    {$R *.dfm}
    type
      TCallModule =  procedure(SS:TADOConnection);stdcall;
    procedure LoadModule(SS:TADOConnection;AModuleName: PChar);
    var
      CallModule: TCallModule;
      FPointer: TFarProc;  LibHandle: HModule;
    begin
        LibHandle := LoadLibrary(AModuleName);
        FPointer := GetProcAddress(LibHandle,'CallModule');
        if FPointer<>nil then
        begin
          CallModule := FPointer;
          CallModule(SS);
        end;
    end;
    procedure TForm1.N3Click(Sender: TObject);
    begin
      self.ADOConnection1.Open;
      if Self.ADOConnection1.Connected then
        Showmessage('ok');
    end;procedure TForm1.N4Click(Sender: TObject);
    begin
      Self.ADOConnection1.Close;
    end;procedure TForm1.N6Click(Sender: TObject);
    begin
      Exit;
    end;procedure TForm1.N2Click(Sender: TObject);
    var s:Widestring;
    begin
      s:=PromptDataSource( Application.Handle,'');
      if s<>'' then
        self.ADOConnection1.ConnectionString:=s;
    end;procedure TForm1.N11Click(Sender: TObject);
    begin
      LoadModule(Self.ADOConnection1, 'MidForm.dll');
    end;end.
    //---------------Unit1.dfmobject Form1: TForm1
      Left = 192
      Top = 114
      Width = 696
      Height = 480
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      FormStyle = fsMDIForm
      Menu = MainMenu1
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object MainMenu1: TMainMenu
        Left = 104
        Top = 248
        object N1: TMenuItem
          Caption = #36830#25509
          object N2: TMenuItem
            Caption = #26356#25913'..'
            OnClick = N2Click
          end
          object N3: TMenuItem
            Caption = #36830#25509
            OnClick = N3Click
          end
          object N4: TMenuItem
            Caption = #26029#24320#36830#25509
            OnClick = N4Click
          end
          object N5: TMenuItem
            Caption = '-'
          end
          object N6: TMenuItem
            Caption = #36864#20986
            OnClick = N6Click
          end
        end
        object N7: TMenuItem
          Caption = #23376#31383#20307
          object N11: TMenuItem
            Caption = #31383#20307'1'
            OnClick = N11Click
          end
        end
      end
      object ADOConnection1: TADOConnection
        Left = 64
        Top = 96
      end
    end
      

  7.   

    两个工程都是用带包编译project-options-package-build with runtime packages
      

  8.   

    朋友,谢谢你的回答,我现在的问题是dll中的Form加载进来后是Parent是Panel,不是直接的调用,如果不指定Parent是可以移动的。问题是动态库的FORM加载进来是到主程序的Panel上的,这样就不能移动。
      

  9.   

    要把Exe和Dll中的Application统一才行吧!
    不然消息传递是有问题的~~~~~~
    呵呵,我猜的~~~~~
      

  10.   

    不是啊,直接加载到主程序的一个Panel上的。
      

  11.   

    加载到Panel上就不行了,看我是怎么调用的
      function f_aa (  siPanel:TPanel;Top,Width,Height,Left:integer):integer;stdcall;
      begin
        Result := 0;
        if Form1=nil then
        Form1:=TForm1.Create(Application);
        Form1.ParentWindow := siPanel.Handle;
        Form1.Left   :=0 ;
        Form1.Top    :=0 ;
        Form1.Width  :=Width ;
        Form1.Height :=Height ;
        Form1.Refresh;
        Form1.show ;
      end
      

  12.   

    我试过加载到panel里面,还是可以在dll里面返回form1的句柄,然后再调用的时候Windows.SetParent()
      

  13.   

    //dll里面function  CallModule(SS:TADOConnection):Hwnd;stdcall;
    begin
      //Coinitialize(nil);
        Ado:=ss;
        if not Assigned(Form1) then
          Form1:=TForm1.Create(application);
        result:=Form1.Handle;
    end;//exe里面type
      TCallModule =  function(SS:TADOConnection):HWND;stdcall;
    function LoadModule(SS:TADOConnection;AModuleName: PChar):HWND;
    var
      CallModule: TCallModule;
      FPointer: TFarProc;  LibHandle: HModule;
    begin
        LibHandle := LoadLibrary(AModuleName);
        FPointer := GetProcAddress(LibHandle,'CallModule');
        if FPointer<>nil then
        begin
          CallModule := FPointer;
          result:=CallModule(SS);
        end
        else
          result:=0;
    end;//载入代码
    Windows.SetParent(LoadModule(Self.ADOConnection1, 'MidForm.dll'),Panel1.Handle);