📄 139.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="7.htm">上一层</a>][<a href="140.htm">下一篇</a>]
<hr><p align="left"><small>发信人: strayli (stray), 信区: Delphi <br>
标 题: How to Circumvent the 'index not found' Exception <br>
发信站: BBS 水木清华站 (Fri Sep 18 13:11:43 1998) <br>
<br>
<br>
KEYWORDS: dbase dbf mdx index not found delphi AREA: All <br>
<br>
Q: How do I open a dBASE table without the required MDX file? <br>
I keep getting an "Index not found..." exception. <br>
<br>
A: When you create a dBASE table with a production index (MDX), a <br>
special byte is set in the header of the DBF file. When you <br>
subsequently attempt to re-open the table, the dBASE driver <br>
will read that special byte, and if it is set, it will also <br>
attempt to open the MDX file. When the MDX file cannot be <br>
opened, an exception is raised. <br>
<br>
To work around this problem, you need to reset the byte (byte <br>
28 decimal) in the DBF file that causes the MDX dependency <br>
to zero. <br>
<br>
The following unit is a simple example of how to handle the <br>
exeption on the table open, reset the byte in the DBF file, <br>
and re-open the table. <br>
<br>
unit Fixit; <br>
<br>
interface <br>
<br>
uses <br>
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, <br>
Controls, Forms, Dialogs, StdCtrls, DB, DBTables, Grids, DBGrids; <br>
<br>
type <br>
TForm1 = class(TForm) <br>
Table1: TTable; <br>
Button1: TButton; <br>
procedure Button1Click(Sender: TObject); <br>
private <br>
{ Private declarations } <br>
public <br>
{ Public declarations } <br>
end; <br>
<br>
var <br>
var <br>
Form1: TForm1; <br>
<br>
implementation <br>
<br>
{$R *.DFM} <br>
<br>
const <br>
TheTableDir = 'c:\temp\'; <br>
TheTableName = 'animals.dbf'; <br>
<br>
procedure RemoveMDXByte(dbFile: String); <br>
{ This procedure accepts a DBF file as a parameter. It will patch} <br>
{ the DBF header, so that it no longer requires the MDX file } <br>
const <br>
Value: Byte = 0; <br>
var <br>
F: File of byte; <br>
begin <br>
AssignFile(F, dbFile); <br>
Reset(F); <br>
Seek(F, 28); <br>
Write(F, Value); <br>
CloseFile(F); <br>
end; <br>
<br>
procedure TForm1.Button1Click(Sender: TObject); <br>
{ This procedure is called in response to a button click. It } <br>
{ attempts to open a table, and, if it can't find the .MDX file, } <br>
{ it patches the DBF file and re-execute the procedure to } <br>
{ re-open the table without the MDX } <br>
begin <br>
try <br>
{ set the directory for the table } <br>
Table1.DatabaseName := TheTableDir; <br>
{ set the table name } <br>
Table1.TableName := TheTableName; <br>
{ attempt to open the table } <br>
Table1.Open; <br>
except <br>
on E:EDBEngineError do <br>
{ The following message indicates the MDX wasn't found: } <br>
if Pos('Index does not exist. File', E.Message)>0 then begin <br>
{ Tell user what's going on. } <br>
MessageDlg('MDX file not found. Attempting to open <br>
Attempting to open <br>
without index.', mtWarning, [mbOk], 0); <br>
{ remove the MDX byte from the table header } <br>
RemoveMDXByte(TheTableDir + TheTableName); <br>
{ Send the button a message to make it think it was } <br>
{ pressed again. Doing so will cause this procedure to } <br>
{ execute again, and the table will be opened without } <br>
{ the MDX } <br>
PostMessage(Button1.Handle, cn_Command, bn_Clicked, 0); <br>
end; <br>
end; <br>
end; <br>
<br>
end. <br>
<br>
<br>
<br>
-- <br>
※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: gps.auto.ustc.e] <br>
</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="7.htm">上一层</a>][<a href="140.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 + -