这段程序是台湾人写的一部分,先写在这儿我也不懂,如果你需要的话,我可以Email给你
Var
isBatch := False;
goAhead := False;
msgStr := '';
if PackTbl then
msgStr := 'Do you want to pack table'
else if IndexTbl then
msgStr := 'Do you want to regenerate indexes for table';
isConnected := Database1.Connected;
if not Database1.Connected then
Database1.Connected := True;
if List1.Count > 1 then
begin
case MessageDlg('Tables in Database "' +
UpperCase(Listbox1.Items[ListBox1.ItemIndex]) +
' " can be processed' + #13 +
'in a batch or individually' + #13 + #13 +
'Do you want to process all tables in a batch?',
mtConfirmation, [mbYes, mbNo], 0) of
mrYes: begin
isBatch := True;
goAhead := True;
end;
mrNo: begin
isBatch := False;
goAhead := False;
end;
end;
end;
for i := 0 to List1.Count - 1 do
begin
Edit1.Text := List1;
ProgressBar1.Position := Trunc(100 * i / (List1.Count));
Application.ProcessMessages;
Table1.TableName := List1;
isActive := Table1.Active;
isExclusive := Table1.Exclusive;
if isBatch = False then
begin
if MessageDlg(msgStr + #13 + #13 + '"' + UpperCase(List1) + '" ?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
goAhead := True
else goAhead := False;
end;
if goAhead then
begin
with Table1 do begin
DisableControls;
try
// ensure that Table's Exclusive property is set to True
// before the Table is opened
Active := False;
Exclusive := True;
Active := True;
// Packing (restructuring) table
if (IsPackTbl = True) then
begin
strcopy(TType, GetTableType(Table1.Handle));
// if it's a Paradox Table
if strcomp(TType, szParadox) = 0 then
PackParadoxTable(Table1)
// else if it's a dBase table then using DbiPackTable()
// to pack tables
else if strcomp(TType, szDBase) = 0 then
rslt := DbiPackTable(DBHandle, Handle, nil, nil, True)
else
MessageDlg('Only dBASE and Paradox tables ' + #13 +
'can be packed or re-indexed',
mtInformation, [mbOK], 0);
end
// Re-generating indexes for both Paradox and dBase tables
else if (IsPackTbl = False) then
rslt := DbiRegenIndexes(Handle);
// Error handling procedure
if (rslt <> DBIERR_NONE) then
begin
errorMsgPtr := @errorMsg;
DbiGetErrorString(rslt, errorMsgPtr);
MessageDlg(errorMsg, mtError, [mbOK], 0);
end;
finally
Active := False;
Exclusive := isExclusive;
Active := isActive;
end; // try ..
EnableControls;
end; // with table1 ..
end; // if goAhead
end; // For ..
Database1.Connected := isConnected;
List1.Free;
ProgressBar1.Position := 0;
if IsPackTbl = True then
Edit1.Text := 'All Tables packed'
else if IsPackTbl = False then
Edit1.Text := 'Re-generating indexes completed';
PackTbl := False;
IndexTbl := False;
BtnStatus;
end;