先删除不能打开表的索引文件
再重建索引
如Table1.addIndex
procedure RepairIndex(TableName:string);
var IndexFileName:string;
DataBaseName:string;
temp:string;
begin
DataBaseName:=ExtractFileDir(application.ExeName)+'/data/'+ChangeFileExt(TableName,'.DB');
if FileExists(DataBaseName)
then begin
{删除原来的索引}
IndexFileName:=ExtractFileDir(application.ExeName)+'/data/'+ChangeFileExt(TableName,'.PX');
if FileExists(IndexFileName)
then begin
DeleteFile(IndexFileName)
end;
{建立新索引}
Table1.TableName:=TableName;
Table1.AddIndex('','编号',[ixPrimary,ixUnique]);
end
else begin
temp:='数据库错误,缺少文件“' + DataBaseName + '”,不能为“'+TableName+'”修复索引!';
MessageDlg(temp, mtError, [mbOk], 0);
is_Success:='false';
end;
end;