⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 236.htm

📁 水木清华的BBS文章
💻 HTM
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://bbs.tsinghua.edu.cn"><font face="黑体"><big><big>水木清华★</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center">         Delphi编程                            (BM: strayli FlyingBoy)          </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p   align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="454"> <p align="center">[<a href="index.htm">回到开始</a>][<a href="182.htm">上一层</a>][<a href="237.htm">下一篇</a>]
<hr><p align="left"><small>发信人: Zeemon (塞下秋), 信区: Visual <br>

标  题: Re: 请大家把编程心得贴出来 <br>

发信站: BBS 水木清华站 (Thu Nov 20 13:18:42 1997) <br>

  <br>

  <br>

  <br>

得到Dataset的当前记录个数 <br>

  <br>

方法一:适用于所有的DataSet。 <br>

If the dataset is based upon a Paradox or dBASE table then the record number <br>

can be determined with a couple of calls to the BDE (as shown below).  The <br>

BDE doesn't support record numbering for datasets based upon SQL tables, so <br>

if your server supports record numbering you will need to refer to its <br>

documentation. <br>

  <br>

The following function takes as its parameter any component derived from <br>

TDataset (i.e. TTable, TQuery, TStoredProc) and returns the current record <br>

number (greater than zero) if it is a Paradox or dBASE table.  Otherwise, <br>

the function returns zero. <br>

  <br>

NOTE: for dBASE tables the record number returned is always the physical <br>

record number.  So, if your dataset is a TQuery or you have a range set <br>

on your dataset then the number returned won't necessarily be relative to <br>



the dataset being viewed, rather it will be based on the record's physical <br>

position in the underlying dBASE table. <br>

  <br>

  <br>

    uses DbiProcs, DbiTypes, DBConsts; <br>

  <br>

    function RecordNumber(Dataset: TDataset): Longint; <br>

    var <br>

      CursorProps: CurProps; <br>

      RecordProps: RECProps; <br>

    begin <br>

      { Return 0 if dataset is not Paradox or dBASE } <br>

      Result := 0; <br>

  <br>

      with Dataset do <br>

      begin <br>

        { Is the dataset active? } <br>

        if State = dsInactive then DBError(SDataSetClosed); <br>

  <br>

        { We need to make this call to grab the cursor's iSeqNums } <br>

        Check(DbiGetCursorProps(Handle, CursorProps)); <br>

  <br>

  <br>

        { Synchronize the BDE cursor with the Dataset's cursor } <br>

        UpdateCursorPos; <br>

  <br>

        { Fill RecordProps with the current record's properties } <br>

        Check(DbiGetRecord(Handle, dbiNOLOCK, nil, @RecordProps)); <br>

  <br>

        { What kind of dataset are we looking at? } <br>

        case CursorProps.iSeqNums of <br>

          0: Result := RecordProps.iPhyRecNum;  { dBASE   } <br>

          1: Result := RecordProps.iSeqNum;     { Paradox } <br>

        end; <br>

      end; <br>

    end; <br>

  <br>

方法二:适用于TTable。 <br>

  <br>

{Retrieves physical record number a la xBase  Requires DBITYPES, DBIPROCS, <br>

 and DBIERRS in the uses clause of the unit.  Function takes one argument <br>

 of type TTable (e.g., Table1).} <br>

function Form1.Recno( oTable: TTable ): Longint; <br>

var <br>

  rError: DBIResult; <br>



  rRecProp: RECprops; <br>

  szErrMsg: DBIMSG; <br>

begin <br>

  Result := 0; <br>

  try <br>

    oTable.UpdateCursorPos; <br>

    rError := DbiGetRecord( oTable.Handle, dbiNOLOCK, nil, @rRecProp ); <br>

    if rError = DBIERR_NONE then <br>

      Result := rRecProp.iPhyRecNum <br>

    else <br>

      case rError of <br>

        DBIERR_BOF: Result := 1; <br>

        DBIERR_EOF: Result := oTable.RecordCount + 1; <br>

        else <br>

        begin <br>

          DbiGetErrorString( rError, szErrMsg ); <br>

          ShowMessage( StrPas( szErrMsg )); <br>

          end; <br>

        end; <br>

  except <br>

    on E: EDBEngineError do ShowMessage( E.Message ); <br>

  end; <br>

sage ); <br>

  end; <br>

end; <br>

  <br>

  <br>

-- <br>

;34m※来源:·西子浣纱城 bbs.zju.edu.cn·[FROM: 210.32.151.241]m <br>

  <br>

-- <br>

※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 162.105.118.41] <br>

</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="182.htm">上一层</a>][<a href="237.htm">下一篇</a>]
<p align="center"><a href="http://cterm.163.net">欢迎访问Cterm主页</a></p>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -