CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
英特尔®游戏设计大赛100美元现金周周送 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  语言基础/算法/系统设计

如何在一个函数单元(MyFunUnit)中写一个所有引用Form的KeyDown事件?

楼主Delphifan()2003-12-03 09:51:31 在 Delphi / 语言基础/算法/系统设计 提问

在每个Form中的组件事件写:  
  OnKeyDown   :=     ToLookup_set_Value;  
  在一个通用单元中写过程:  
  procedure   ToLookup_set_Value(Sender:   TObject;   var   Key:   Word;  
      Shift:   TShiftState)   ;  
  var  
      i:   integer;  
      APPID,   DOCID,   tmpStr:   string;  
  begin  
      //可以更改Internal的值  
      if     Key   =   13     then  
          with   (Sender   as   TDBLookupCombobox)   do  
          begin  
              end;  
          end  
      else   if   (Key   =   VK_F9)   (*and   (shift   =   [ssctrl])*)   then  
      begin  
      end  
          //关闭机车数据编辑以后,刷新该数据记  
      else   if   (Key   =   VK_F5)   and   (Sender   is   TDBLookupCombobox)   then  
          with   (Sender   as   TDBLookupCombobox).ListSource.DataSet   do  
          try  
              Wait;  
              Close;  
              Open;  
          finally  
              wait(false);  
          end;  
  end;  
  问题点数:0、回复次数:6Top

1 楼Delphifan()回复于 2003-12-03 09:54:02 得分 0

提示的出错信息为——  
  【Incompatible   types:   'method   pointer   and   regular   procedure'】Top

2 楼jacky_shen(jacky)回复于 2003-12-03 23:59:15 得分 0

if   you   want   to   reference   a   method   of   an   instance   object   (see   Classes   and   objects),   you   need   to   add   the   words   of   object   to   the   procedural   type   name.   For   example  
   
  type  
   
      TMethod   =   procedure   of   object;  
      TNotifyEvent   =   procedure(Sender:   TObject)   of   object;  
   
  These   types   represent   method   pointers.   A   method   pointer   is   really   a   pair   of   pointers;   the   first   stores   the   address   of   a   method,   and   the   second   stores   a   reference   to   the   object   the   method   belongs   to.   Given   the   declarations  
   
  type  
   
      TNotifyEvent   =   procedure(Sender:   TObject)   of   object;  
      TMainForm   =   class(TForm)  
          procedure   ButtonClick(Sender:   TObject);  
          ...  
      end;  
  var  
      MainForm:   TMainForm;  
      OnClick:   TNotifyEvent  
   
  we   could   make   the   following   assignment.  
   
  OnClick   :=   MainForm.ButtonClick;  
   
  Two   procedural   types   are   compatible   if   they   have  
   
  the   same   calling   convention,  
  the   same   return   value   (or   no   return   value),   and  
  the   same   number   of   parameters,   with   identically   typed   parameters   in   corresponding   positions.   (Parameter   names   do   not   matter.)  
   
  Procedure   pointer   types   are   always   incompatible   with   method   pointer   types.   The   value   nil   can   be   assigned   to   any   procedural   type.  
  Nested   procedures   and   functions   (routines   declared   within   other   routines)   cannot   be   used   as   procedural   values,   nor   can   predefined   procedures   and   functions.   If   you   want   to   use   a   predefined   routine   like   Length   as   a   procedural   value,   write   a   wrapper   for   it:  
   
  function   FLength(S:   string):   Integer;  
   
  begin  
      Result   :=   Length(S);  
  end;  
   
  Procedural   types   in   statements   and   expressionsTop

3 楼HGRhgr(HGRhgr)回复于 2003-12-08 10:27:42 得分 0

OnKeyDown   :=     ToLookup_set_Value;  
  要使等式成立,必须使得等式左右类型相同,  
  由于OnKeyDown是个对象方法,所以ToLookup_set_Value也必须要定义成对象方法Top

4 楼qiume(好好回贴,天天胖胖)回复于 2003-12-08 14:22:20 得分 0

类型不匹配Top

5 楼acai(acai)回复于 2003-12-10 17:47:56 得分 0

可以做到的,把你的代码修改为:  
  //在每个Form中的组件事件写:  
  //OnKeyDown   :=     ToLookup_set_Value;  
   
  var  
      M:   TMethod;  
  begin  
      M.Code   :=   @ToLookup_set_Value;  
      YourComponent.OnKeyDown   =   TKeyEvent(M);  
  end;  
  Top

6 楼delphi2java(delphi2java)回复于 2003-12-10 17:51:59 得分 0

用application中的消息来控制比较方便。Top

相关问题

  • 计算单元格个数的函数
  • 如何查找API函数所属的单元?
  • Delphi6 数学单元(math.pas)中的函数错误!!!
  • 使用RegisterServiceProcess函数应增加哪个单元?不是TLHelp32吗?
  • 请问,CreateOleObject函数在那个单元定义的?
  • cppunit做单元测试时如何处理被测函数调用其他函数的情况?
  • 小弟现有一个放函数文件的单元 可不可以把这个单元的所有函数放到一个控件里.....
  • 程序中有的需要一些单元,怎样才能知道是什么函数和在什么单元!?
  • 调用独立单元函数,运行出错,大容量题目
  • 在EXCEL2000单元格中有没有设置页数和总页数的函数?

关键词

  • tdblookupcombobox
  • sender
  • procedure
  • key
  • begin
  • then
  • object

得分解答快速导航

  • 帖主:Delphifan

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo