当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: edit控件的彈出菜單怎樣屏蔽,請給例子! ......
    摘要: 如何在vb程序中创建access数据库 谢了 ......


在DELPHI中怎么样保存到一个记录的位置

 
        我遇到这样的事情,就是在访问数据库的时候,有时需要把当前的这个记录的位置保存下来,因为在后来的访问操作中,我有可能要回到这一个保存点,该怎么实现?是不是用Bookmark?怎么用?

NO.1   作者: guestman

看看下面的代码,也许对你有帮助·  
  This   example   uses   a   button   to   copy   the   value   of   a   field   in   the   previous   record   into   the   corresponding   field   in   the   current   record.    
   
  procedure   TForm1.CopyDataClick(Sender:   TObject);  
   
  var  
        SavePlace:   TBookmark;  
        PrevValue:   Variant;  
  begin  
        with   Table1   do  
        begin  
          {   get   a   bookmark   so   that   we   can   return   to   the   same   record   }  
          SavePlace   :=   GetBookmark;  
   
          {   move   to   prior   record}  
   
          FindPrior;    
   
          {   get   the   value   }  
   
          PrevValue   :=   Fields[0].Value;  
   
          {Move   back   to   the   bookmark    
   
          this   may   not   be   the   next   record   anymore    
          if   something   else   is   changing   the   dataset   asynchronously   }  
          GotoBookmark(SavePlace);  
          {   Set   the   value   }  
          Fields[0].Value   :=   PrevValue;  
          {   Free   the   bookmark   }  
          FreeBookmark(SavePlace);  
      end;  
   
  end;  
   
  To   ensure   that   the   button   is   disabled   when   there   is   no   previous   record,   the   OnDataChange   event   of   the   DataSource   detects   when   the   user   moves   to   the   beginning   of   file   (BOF   property   becomes   True),   and   disables   the   button.  
   
  procedure   TForm1.Table1DataChange(Sender:   TObject;   Field:   TField);  
   
  begin  
      if   Table1.BOF   then  
          CopyData.Enabled   :=   False  
      else  
          CopyData.Enabled   :=   True;  
  end;

NO.2   作者: haoco

是的,如下:  
   
  var  
        SavePlace:   TBookmark;//要定义一个用于保存这个点的变量  
        PrevValue:   Variant;  
  begin  
        withClientDataSet1   do  
        begin  
          SavePlace   :=   GetBookmark;  
          try  
              .......................  
              GotoBookmark(SavePlace);//回到原来的记录  
          finally  
              FreeBookmark(SavePlace);//释放这个变量  
          end;  
      end;


    摘要: 可能是后面两个中文字被截取?应该追加什么? ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE