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

📄 在delphi 中 利 用 tbatch 组 件.htm

📁 对于学习很有帮助
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Welcome to Delphi Tips !</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<link rel="stylesheet" href="../tips.css"></head>

<body bgcolor="#D8D0C8" text="#675350">
<div align="left"> 
  <table border="1" cellpadding="0" cellspacing="0" width="579" height="63" bordercolorlight="#784400" bordercolordark="#D8D0C8">
    <tr>
      <td width="194" height="86"><img src="../images/title.gif" width="340" height="85"></td>
      <td width="377" height="86" valign="top"><img src="../images/dong.jpg" width="251" height="85"> 
	&nbsp;&nbsp;</td>
  </tr>
</table>
  <br>
</div>
<div align="left">

  <table border="1" cellpadding="0" cellspacing="0" width="578" height="18" bordercolorlight="#784400" bordercolordark="#CCCCCC" class="p2">
    <tr bgcolor="#B0A498"> 
      <td width="574" height="18"> &gt;<a href="../index.htm">DelphiTips首页</a> 
	&gt; <a href="main.htm">控件应用</a></td>
  </tr>
</table>
  <br>
  <table width="96%" border="1" bordercolorlight="#784400" cellspacing="0" bordercolordark="#D8D0C8">
    <tr bgcolor="#B0A498" class="p1"> 
      <td colspan="3" height="16"> 
	<div align="center">在Delphi 中 利 用 Tbatch 组 件</div>
      </td>
      <td width="12%" class="p2" height="16">&lt;&lt;<a href="002.htm">上一篇</a></td>
      <td width="13%" class="p2" height="16"><a href="004.htm">下一篇</a>&gt;&gt;</td>
    </tr>
    <tr class="p2"> 
      <td colspan="5">
	<table width="100%" border="0" class="p2">
	  <tr>
	    <td width="3%">&nbsp;</td>
	    <td width="94%">
	      <p><span style="font-size: 9pt">---- 在 数 据 库 应 用 系 统 中, 常 常 要 对 
		数 据 进 行 成 批 的 如 追 加、 删 除、 更 改 等<br>
		操 作, 这 种 批 量 操 作 在 专 门 的 数 据 库 开 发 工 具 如VFP 中 用APPEND 、COPY 命 
		令<br>
		带 上 相 应 的 命 令 子 句 就 能 轻 易 完 成。 但 在 其 它 开 发 工 具 中 并 没 有 类 似 的<br>
		命 令, 而 是 提 供 能 完 成 类 似 功 能 的 控 件 或 对 象, 如 在PowerBuilder 中 就 是 
		利 用<br>
		Pipe Line( 数 据 管 道) 来 完 成 两 个 或 同 构 或 不 同 构 的 表 之 间 的 数 据 批 处 
		理。 <br>
		本 文 要 介 绍 的 是Delphi 中 用 来 完 成 数 据 批 处 理 任 务 的 组 件TBatchMove。TBatchMove 
		组<br>
		件 能 够: <br>
		</span></p>
	      <p><span style="font-size: 9pt">将 一 个 数 据 集 中 的 数 据 追 加 到 一 个 表 
		中。. <br>
		</span> 
	      <ul>
		<li><span style="font-size: 9pt">从 一 个 表 中 删 除 满 足 条 件 的 记 录。 
		  <br>
		  </span></li>
		<li><span style="font-size: 9pt">按 旧 表 结 构 生 成 一 个 新 表, 若 欲 生 
		  成 的 新 表 已 存 在, 则 覆 盖。 </span></li>
	      </ul>
	      <p><font color="#ffffff"><span style="font-size: 9pt"> </span></font></p>
	      <p> <font color="#ffffff"><span style="font-size: 9pt">----</span></font><span style="font-size: 9pt"> 
		具 体 的 操 作 要 通 过 设 置TBatchMove 的Mode 属 性 后 再 调 用Execute 方 法 来 完 
		成。 为<br>
		举 例 说 明 问 题, 我 们 在 别 名 数 据 库DBDEMOS 中 先 创 建 两 个dBase 格 式 的 表Test1.dbf<br>
		和Test2.dbf。 二 者 的 结 构 如 下 表:</span></p>
	      <pre><span style="font-size: 9pt">    Test1.dbf	Test2.dbf
    Name	C	10	Name	C	10
    Code	C	3	Code	C	3</span></pre>
	      <p><font color="#ffffff"><span style="font-size: 9pt"> </span></font></p>
	      <p> <font color="#ffffff"><span style="font-size: 9pt">----</span></font><span style="font-size: 9pt"> 
		其 中 表Test2.dbf 在 字 段code 上 建 立 有 唯 一 索 引。 同 时 假 设 表 单 中 已 有 两 
		个<br>
		TABLE 控 件Tsource 和Tdest 和 一 个TbatchMove 组 件batchmove1。Tsource 
		和Tdest 的DatabaseName 属 性 均<br>
		设 为DBDEMOS。batchmove1 的source 属 性 设 为Tsource,destination 属 性 设 
		为Tdest。<br>
		<font color="#ffffff">----</font> 在 使 用TbatchMove 组 件 时, 必 须 牢 
		记: 所 有 的 操 作 都 是 以 源 表 为 标 准 针 对 目<br>
		的 表 进 行 的, 下 面 就 分 别 举 例 说 明TbatchMove 的 各 种 操 作 模 式: </span> 
	      <ul>
		<li><span style="font-size: 9pt"><b>batAppend 追 加 模 式</b> 将 源 
		  表 中 的 数 据 追 加 到 目 的 表 中, 目 的 表 必 须 事 先 存<br>
		  在。 这 是 缺 省 模 式。 <br>
		  batchmove1.source=Tsource; <br>
		  batchmove1.destination=Tdest2 ; <br>
		  batchmove1.Mode:=batCopy; <br>
		  batchmove1.Execute; <br>
		  </span></li>
		<li><span style="font-size: 9pt"><b>batUpdate 更 新 模 式</b> 用 源 
		  表 中 匹 配 目 的 表 的 记 录 替 换 目 的 表 中 的 相 应 记<br>
		  录。 目 的 表 必 须 事 先 存 在 且 有 一 已 定 义 的 索 引 用 来 匹 配 源 表 中 的 记<br>
		  录。 <br>
		  Tdest.IndexFieldNames:='code'; <br>
		  batchmove1.source=Tsource; <br>
		  batchmove1.destination=Tdest ; <br>
		  batchmove1.Mode:=batUpdate; <br>
		  batchmove1.Execute; <br>
		  </span></li>
		<li><span style="font-size: 9pt"><b>batAppendUpdate 追 加 更 新 模 
		  式 </b>如 果 源 表 中 有 与 目 的 表 匹 配 的 记 录, 则 替 换<br>
		  目 的 表 记 录, 否 则, 直 接 追 加 到 目 的 表 中。 目 的 表 必 须 事 先 存 在 且 有 一<br>
		  已 定 义 的 索 引 用 来 匹 配 源 表 中 的 记 录。 <br>
		  Tdest.IndexFieldNames:='code'; <br>
		  batchmove1.source=Tsource; <br>
		  batchmove1.destination=Tdest ; <br>
		  batchmove1.Mode:=batAppendUpdate; <br>
		  batchmove1.Execute; <br>
		  </span></li>
		<li><span style="font-size: 9pt"><b>batCopy 拷 贝 模 式</b> 按 源 表 
		  结 构 生 成 新 表, 源 表 中 的 数 据 同 时 拷 贝 到 目 的<br>
		  新 表 中。 如 果 要 生 成 的 新 表 已 存 在, 则 覆 盖。 <br>
		  // 按Test1.dbf 生 成 新 表xxx.dbf <br>
		  // 如 果 不 指 定 扩 展 名dbf, 生 成 的 新 表 将 是Paradox 格 式 的xxx.db。 <br>
		  Tdest.TableName:='xxx.dbf'; <br>
		  batchmove1.source=Tsource; <br>
		  batchmove1.destination=Tdest ; <br>
		  batchmove1.Mode:=batCopy; <br>
		  batchmove1.Execute; <br>
		  </span></li>
		<li><span style="font-size: 9pt"><b>batDelete 删 除 模 式</b> 删 除 
		  目 的 表 中 与 源 表 匹 配 的 记 录。 目 的 表 必 须 事 先 存<br>
		  在 且 有 一 已 定 义 的 索 引 用 来 匹 配 源 表 中 的 记 录。 <br>
		  Tdest.IndexFieldNames:='code'; <br>
		  batchmove1.source=Tsource; <br>
		  batchmove1.destination=Tdest ; <br>
		  batchmove1.Mode:=batDelete; <br>
		  batchmove1.Execute; </span></li>
	      </ul>
	      <p><font color="#ffffff"><span style="font-size: 9pt"> </span></font></p>
	      <p> <font color="#ffffff"><span style="font-size: 9pt">----</span></font><span style="font-size: 9pt"> 
		TBatchMove 还 有 一 个 重 要 属 性ChangedTableName, 在 实 际 运 用 中, 通 过 指 
		定<br>
		ChangedTableName 属 性 可 以 创 建 一 个Paradox 表, 该 表 用 来 保 存 目 的 表 中 
		被 更 改 数 据<br>
		的 原 始 备 份, 有 了 这 个 备 份 表 就 可 以 确 保 恢 复 目 的 表 中 的 数 据。 </span></p>
	      <p><span style="font-size: 9pt"><font color="#ffffff">----</font> 
		顺 便 提 一 句, 如 果 要 删 除 某 一 个 表 中 的 全 部 记 录, 可 以 采 用Table 组 件 的<br>
		EmptyTable 方 法, 例 如Tdest.EmptyTable 将 清 空Tdest 所 指 定 的 表test2.dbf。 
		</span></p>
	      <p><span style="font-size: 9pt"><font color="#ffffff">----</font> 
		本 文 中 是 以 同 构 的dbf 表 进 行 的 示 例, 在 实 际 运 用 中, 源 表 和 目 的 表 可 能<br>
		同 购, 也 可 能 异 构, 异 构 时,Delphi 的BDE 会 自 动 进 行 类 型 和 长 度 上 的 转 换, 
		具<br>
		体 类 型 间 的 关 系 可 以 有 关BDE 的 帮 助。 本 文 中 各 种 操 作 模 式 的 实 际 结 果 均<br>
		可 以 从Delphi 的Database Desktop 中 查 看 到。 </span></p>
	    </td>
	    <td width="3%">&nbsp;</td>
	  </tr>
	</table>
      </td>
    </tr>
    <tr bgcolor="#B0A498" class="p2"> 
      <td height="22" width="61%" colspan="2">&nbsp; <marquee behavior="alternate">如果你有什么好的资料,可以寄给我哟:)</marquee></td>
      <td height="22" width="14%"><a href="../index.htm">&lt;&lt;回到首页</a></td>
      <td height="22" width="12%">&lt;&lt;<a href="002.htm">上一篇</a></td>
      <td height="22" width="13%"><a href="004.htm">下一篇</a>&gt;&gt;</td>
    </tr>
  </table>
  <br>
  <br>
  <hr size=1 noshade width=500>
  <table width="75%" border="0" align="center" class="p2">
    <tr> 
      <td colspan="2">&nbsp;</td>
      <td width="24%">
	<table width="95%" border="1" bordercolorlight="#663300" bordercolordark="#CCCCCC" cellspacing="0" class="p2">
	  <tr>
	    <td>
	      <div align="center">Delphi 技巧集</div>
	    </td>
	  </tr>
	</table>
      </td>
      <td width="38%">&nbsp;</td>
    </tr>
    <tr> 
      <td width="16%">&nbsp;</td>
      <td colspan="2">Copyright 1999.11 by 东子</td>
      <td width="38%"><a href="../jintongbao@188.net">Mail to me!</a></td>
    </tr>
    <tr> 
      <td colspan="4"> 
	<div align="center">感谢广州视窗提供主页空间</div>
      </td>
    </tr>
  </table>
  <br>
</div><div align="center"><center>
  </center></div>
</body>
</html>

⌨️ 快捷键说明

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