CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

求教一个拦截事件的方法

楼主sea_way(狒狒)2003-06-01 15:32:41 在 Delphi / VCL组件开发及应用 提问

求教一个拦截事件的方法    
       
  有个窗体向一个TABLE中添加记录,添加删除的按钮用用了映射插入记录的功能,DELPHI7    
  所以不用写一个代码也能插入删除,编辑记录,但我想让再删除记录时候提示一个MESSAGE    
  问是否删除,如果不删除就不进行删除记录操作,但我是映射的插入记录操作.这时候怎么    
  做才能实现上面的功能?    
     
  问题点数:100、回复次数:7Top

1 楼sea_way(狒狒)回复于 2003-06-01 15:42:02 得分 0

知道的请赐教.Top

2 楼microjuz(天才弟弟……》说好了和xgto看流星雨)回复于 2003-06-01 15:57:40 得分 10

你用的dbgrid吗  
  你说的映射是不是  
    DBNavigator1.BtnClick(nbFirst);这种样子  
  那你在这条语句前面插入一个messagedlg不就可以了吗Top

3 楼feng93017(Edge)回复于 2003-06-01 16:32:00 得分 50

你的想法很好!  
  但是一般来说,我见过的软件,绝大多数都是自己在Button的Click事件里面写代码。  
  因为这样可以灵活的处理很多实际情况。而且,这些组合按钮连标题都没有。用户使用不是很直观。  
  更不要说是漂亮的界面了。  
  但是出于交流技术的角度,我的建议是自己写一个控件,从DBNavigator继承下来。下面是我的部分代码以供参考。  
  ==================================================================  
  .....  
   
  const  
      InsertRecordQuestion   =   '确实要添加么?';  
      EditRecordQuestion   =   '确实要修改么?';  
   
      ......  
      public  
          procedure   BtnClick(Index:   TNavigateBtn);   override;  
      ......  
   
  procedure   TDBNavigator.BtnClick(Index:   TNavigateBtn);  
  begin  
      case   Index   of  
          nbInsert:  
              if   (MessageDlg(InsertRecordQuestion,   mtConfirmation,  
                  mbOKCancel,   0)   =   idCancel)   then   exit;  
          nbEdit:   Edit;  
              if   (MessageDlg(EditRecordQuestion,   mtConfirmation,  
                  mbOKCancel,   0)   =   idCancel)   then   exit;  
          //至于Delete方法,该控建议经有这一项属性,不必多此一举。  
      end;  
   
      inherited;     //这一句很重要,否则将不能执行父类的动作。  
  end;Top

4 楼feng93017(Edge)回复于 2003-06-01 16:39:00 得分 40

有个地方写错了。  
  nbEdit:   Edit;     //这里的   (   :Edit;)是多余的。应该去掉。  
              if   (MessageDlg(EditRecordQuestion,   mtConfirmation,  
                  mbOKCancel,   0)   =   idCancel)   then   exit;  
   
  建议参考TDBNavigator的源代码。你甚至可以修改它源代码。这样,你就不用另外写一个控见了。因为你的要求很简单,只是要一个提示框。你可以参考它的下面这个事件。其实,我也是参考这个事件才给除了上面的代码。  
  procedure   TDBNavigator.BtnClick(Index:   TNavigateBtn);  
  begin  
      if   (DataSource   <>   nil)   and   (DataSource.State   <>   dsInactive)   then  
      begin  
          if   not   (csDesigning   in   ComponentState)   and   Assigned(FBeforeAction)   then  
              FBeforeAction(Self,   Index);  
          with   DataSource.DataSet   do  
          begin  
              case   Index   of  
                  nbPrior:   Prior;  
                  nbNext:   Next;  
                  nbFirst:   First;  
                  nbLast:   Last;  
                  nbInsert:   Insert;  
                  nbEdit:   Edit;  
                  nbCancel:   Cancel;  
                  nbPost:   Post;  
                  nbRefresh:   Refresh;  
                  nbDelete:     //下面的代码可以用同样的方式写在它的Insert,   和Edit事件里面。  
                      if   not   FConfirmDelete   or  
                          (MessageDlg(SDeleteRecordQuestion,   mtConfirmation,  
                          mbOKCancel,   0)   <>   idCancel)   then   Delete;  
              end;  
          end;  
      end;  
      if   not   (csDesigning   in   ComponentState)   and   Assigned(FOnNavClick)   then  
          FOnNavClick(Self,   Index);  
  end;  
  Top

5 楼yb3721(yb)回复于 2003-06-01 16:59:17 得分 0

to   feng93017(Edge)   :  
  问个简单问题:  
  with...do   是什么意思   有什么用   我前年学过c++   builder   现在转过来学delphi,工作需要Top

6 楼feng93017(Edge)回复于 2003-06-01 18:03:19 得分 0

A   with   statement   is   a   shorthand   for   referencing   the   fields   of   a   record   or   the   fields,   properties,   and   methods   of   an   object.   The   syntax   of   a   with   statement   is  
   
  with   obj   do   statement  
   
  or  
   
  with   obj1,   ...,   objn   do   statement  
   
  where   obj   is   a   variable   reference   denoting   an   object   or   record,   and   statement   is   any   simple   or   structured   statement.   Within   statement,   you   can   refer   to   fields,   properties,   and   methods   of   obj   using   their   identifiers   alone梬ithout   qualifiers.  
  For   example,   given   the   declarations  
   
  type   TDate   =   record  
   
      Day:   Integer;  
      Month:   Integer;  
      Year:   Integer;  
  end;  
   
  var   OrderDate:   TDate;  
   
  you   could   write   the   following   with   statement.  
   
  with   OrderDate   do  
   
      if   Month   =   12   then  
      begin  
          Month   :=   1;  
          Year   :=   Year   +   1;  
      end  
      else  
          Month   :=   Month   +   1;  
   
  This   is   equivalent   to  
   
  if   OrderDate.Month   =   12   then  
   
  begin  
      OrderDate.Month   :=   1;  
      OrderDate.Year   :=   OrderDate.Year   +   1;  
  end  
  else  
      OrderDate.Month   :=   OrderDate.Month   +   1;  
   
  If   the   interpretation   of   obj   involves   indexing   arrays   or   dereferencing   pointers,   these   actions   are   performed   once,   before   statement   is   executed.   This   makes   with   statements   efficient   as   well   as   concise.   It   also   means   that   assignments   to   a   variable   within   statement   cannot   affect   the   interpretation   of   obj   during   the   current   execution   of   the   with   statement.  
  Each   variable   reference   or   method   name   in   a   with   statement   is   interpreted,   if   possible,   as   a   member   of   the   specified   object   or   record.   If   there   is   another   variable   or   method   of   the   same   name   that   you   want   to   access   from   the   with   statement,   you   need   to   prepend   it   with   a   qualifier,   as   in   the   following   example.  
   
  with   OrderDate   do  
   
      begin  
          Year   :=   Unit1.Year  
          ...  
      end;  
   
  When   multiple   objects   or   records   appear   after   with,   the   entire   statement   is   treated   like   a   series   of   nested   with   statements.   Thus  
   
  with   obj1,   obj2,   ...,   objn   do   statement  
   
  is   equivalent   to  
   
  with   obj1   do  
   
      with   obj2   do  
            ...    
            with   objn   do  
                statement  
   
  In   this   case,   each   variable   reference   or   method   name   in   statement   is   interpreted,   if   possible,   as   a   member   of   objn;   otherwise   it   is   interpreted,   if   possible,   as   a   member   of   objn?;   and   so   forth.   The   same   rule   applies   to   interpreting   the   objs   themselves,   so   that,   for   instance,   if   objn   is   a   member   of   both   obj1   and   obj2,   it   is   interpreted   as   obj2.objn.Top

7 楼microjuz(天才弟弟……》说好了和xgto看流星雨)回复于 2003-06-04 16:04:35 得分 0

我也要试着自己写组件,呵呵  
  我不太喜欢用with..do..读代码的时候感觉很不爽  
  with..do..的用法  
   
  原来的代码  
  component1.function1;  
  component1.property1   :=   ^^^^;  
  component1.property2   :=^^^^^;  
   
  用with..do..  
  with   component1   do  
  begin  
  function1;  
  property1   :=   ^^^^;  
  property2   :=^^^^^;  
  end;  
  明白了吗?  
  Top

相关问题

  • 拦截所有的事件(Mouse,Keyboard)
  • 钩——拦截所有的事件(Mouse,Keyboard)
  • 怎样拦截HTML链接CLICK事件?
  • 如何拦截editbox的双击事件?
  • 高分请教一个asp.net事件拦截的问题。另附赠一个对用户来说很有好的超时处理方法。
  • text文本框控件如何拦截“PgUp、PgDn、Up、DoWn”事件
  • 程序控制问题:如何拦截TEdit的Exit事件。
  • 怎样拦截FORM的最小化事件?
  • 请教:如何拦截窗体的OnClick()或OnMouseDown事件?
  • 为什么不能拦截ADODB控件的事件

关键词

  • 代码
  • 映射
  • mbokcancel
  • messagedlg
  • mtconfirmation
  • btnclick
  • editrecordquestion
  • nbedit
  • tnavigatebtn
  • 删除

得分解答快速导航

  • 帖主:sea_way
  • microjuz
  • feng93017
  • feng93017

相关链接

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

广告也精彩

反馈

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