MDI的框架结构中,子窗体中的DBGrid组件不能响应Click事件(200分)

  • 主题发起人 主题发起人 allai
  • 开始时间 开始时间
A

allai

Unregistered / Unconfirmed
GUEST, unregistred user!
下面是一个小程序的整个编写过程!
建立二个窗体Form1,form2
form1的窗体风格(formstyle)属性改为MDIForm
form1窗体中加入ListView控件,使之位置为最左边
在form1中加入uses unit2;

form2的窗体风格属性改为MDIChild
form2窗体中加入DBGrid组件。
运行程序
当看到两个窗体都出现后,
1)双击form2的DBGrid控件,响应正常。
2)点击一下form1的ListView控件,再直接双击form2窗体中DBGrid控件(不要先点击Form2窗体中其它部分),DBGrid没有响应!
3)如果先点击form2窗体其它部分,再双击DBGrid窗体就响应了。
再做如下动作:
先点击窗体中form2的其他控件,如一个button, 再直接点击form2中DBGrid控件,DBGrid控件就能马上响应!
这是Delphi本身的bug,还是我用的不对。 望大家解答。
-------------------------------------------------------------
没法上传附件,只能贴上我的代码:
代码:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, Menus, ExtCtrls;
type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel1: TPanel;
    Splitter1: TSplitter;
    ListView1: TListView;
    MDIForm1: TMenuItem;
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
uses
  Unit2;
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
   
  if not assigned(Form2) then
    Form2 := TForm2.Create(Application);
  Form2.Show();
end;
end.
代码:
unit Unit2;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, Grids, DBGrids, ExtCtrls;
type
  TForm2 = class(TForm)
    DBGrid1: TDBGrid;
    Button1: TButton;
    procedure DBGrid1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.DBGrid1DblClick(Sender: TObject);
begin
  showmessage('DBGrid DblClick OK!!!');
end;
end.
代码:
program Project1;
uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
--------------------------------------------------
 
后退
顶部