比如某个TQuery,我只知道其名字为Query1,它定义了很多事件,包括OnBeforepost,OnAfterScroll,OnBeforeEdit,OnNewRecord.....等,至于具体是哪些事件也是不确定的,有没有什么办法一次性把它所有的事件屏蔽掉,当然,控件还是存在并且有效的,只是不会触发任何事件。

解决方案 »

  1.   

    以下是我编写的函数,以前回答过类似的问题,现在把它贴出来:
    //使用 GetPropCount 可取得控件的的属性计数:function GetPropCount(Instance: TPersistent): Integer;
    var
      Data: PTypeData;
    begin
      Data := GetTypeData(Instance.Classinfo);
      Result := Data^.PropCount;
    end;//使用 GetPropName 可取得属性的名称:function GetPropName(Instance: TPersistent; Index: Integer): string;
    var
      PropList: PPropList;
      PropInfo: PPropInfo;
      Data: PTypeData;
    begin
      Result := '';
      Data := GetTypeData(Instance.Classinfo);
      GetMem(PropList, Data^.PropCount * Sizeof(PPropInfo));
      try
        GetPropInfos(Instance.ClassInfo, PropList);
        PropInfo := PropList^[Index];
        Result := PropInfo^.Name;
      finally
        FreeMem(PropList, Data^.PropCount * Sizeof(PPropInfo));
      end;
    end;procedure CloseForm(Form: TForm);
    var
      Index: Integer;
      src: TPersistent;
      SrcPropInfo: PPropInfo;
      MyMethod: TMethod;
      j: integer;
    begin
      with Form do
      begin
        for j := 0 to ComponentCount - 1 do
        begin
          src := TPersistent(Components[j]);
          for Index := 0 to GetPropCount(Src) - 1 do
          begin
            SrcPropInfo := GetPropInfo(Src.ClassInfo, GetPropName(Src, Index));
            if (srcPropInfo <> nil) and (SrcPropInfo^.PropType^.Kind = tkMethod)
              then
            begin
              MyMethod := GetMethodProp(Src, SrcPropInfo);
              if (Assigned(MyMethod.Data)) and (Assigned(MyMethod.Code)) then
              begin
                MyMethod.Data := nil;
                MyMethod.Code := nil;
                SetMethodProp(Src, SrcPropInfo, MyMethod);
              end;
            end;
          end;
        end;
      end;
    end;
      

  2.   

    {=======================================================================
            作者: zsy_good
            时间: 2002/10/01 17:45:00
            地点: 哈尔滨
            功能: 截获指定的windows消息更改后送出
    ========================================================================}//
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, ComCtrls;type
      TForm1 = class(TForm)
        PageControl1: TPageControl;
        TabSheet1: TTabSheet;
        TabSheet2: TTabSheet;
        TabSheet3: TTabSheet;
        TabSheet4: TTabSheet;
        TabSheet5: TTabSheet;
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
         OldWndProc: Pointer;
        WndProcPtr: Pointer;
        procedure FormDestroy(Sender: TObject);
        procedure WndMethod(var Msg: TMessage);
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      deleted: Boolean;
      Curpageindex: integer;
    implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
    begin
      WndProcPtr := MakeObjectInstance(WndMethod);
      OldWndProc := Pointer(SetWindowLong(pagecontrol1.Handle, GWL_WNDPROC,
        Integer(WndProcPtr)));
    end;
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      SetWindowLong(pagecontrol1.Handle, GWL_WNDPROC, Longint(OldWndProc));
      FreeObjectInstance(WndProcPtr);
    end;
    procedure TForm1.WndMethod(var Msg: TMessage);
    begin
      if Msg.Msg = 4872 then
      begin
        deleted:=True;
        Curpageindex:=pagecontrol1.ActivePageIndex ;
      end
      else if Msg.Msg =4876 then
      begin
        if (deleted) and (Msg.WParam = Curpageindex+1 ) then
        begin
          Msg.WParam := CurPageindex;
          deleted:=False;
        end;
      end;
      with Msg do
        Result := CallWindowProc(OldWndProc, Application.Handle, Msg, wParam,
          lParam);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      pagecontrol1.Pages[3].PageControl := nil;
    end;end.
      

  3.   

    只要
    if msg.msg <> 0 then 
      exit;  //不管任何消息都吃掉with Msg do
        Result := CallWindowProc(OldWndProc, Application.Handle, Msg, wParam,lParam);  //不想吃掉交还给windows处理