yysun
asked on
*.mdx lost problem (dBase 7)
Hi,
If the *.mdx files lost, I used to set the byte number 28 to 0 in *.dbf file.
But Dbase 7 changed DBF file structure. How can I do with it?
Or I think using BDE API is better than to modify the file physically.
Thanks.
If the *.mdx files lost, I used to set the byte number 28 to 0 in *.dbf file.
But Dbase 7 changed DBF file structure. How can I do with it?
Or I think using BDE API is better than to modify the file physically.
Thanks.
ASKER
ÄúºÃ£¡dwwang,¾ÓÈ»µ½ÕâÀïÀ´· ¢²ÆÁË£¿
I've alreadyed check that document, but all the functions there should use a valid handle of the table. But if the mdx file missed the table can not be opened. So no handle can be used?
What can I do then?
I've alreadyed check that document, but all the functions there should use a valid handle of the table. But if the mdx file missed the table can not be opened. So no handle can be used?
What can I do then?
Is it not possible to rebuild the index files from info within the table ?
Darren
Darren
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
How can I do it using Delphi like Database Desktop does?
Have a look at TTable.DeleteIndex and TTable.IndexDef methods and properties.
you could also call the BDE directly. Below is a block of code that was given to me as an answer on E-E for compacting dBase and Paradox tables. There's a bit in it that uses the BDE to re-index and re-structure the tables. Maybe this is of some use.
unit DBPack;
interface
uses BDE, DBTables, DB, sysutils;
procedure PackTable(Table: TTable);
implementation
// This example will pack a Paradox or dBASE table therfore removing already deleted rows in a table.
// This function will also regenerate all out-of-date indexes (maintained indexes).
// This example uses the following input:
// PackTable(Table1)
// The function is defined as follows:
// Pack a Paradox or dBASE table
// The table must be opened execlusively before calling this function...
procedure PackTable(Table: TTable);
var
Props: CURProps;
hDb: hDBIDb;
TableDesc: CRTblDesc;
begin
// Make sure the table is open exclusively so we can get the db handle...
if Table.Active = False then raise EDatabaseError.Create('Tab le must be opened to pack');
if Table.Exclusive = False then raise EDatabaseError.Create('Tab le must be opened exclusively to pack');
// Get the table properties to determine table type...
Check(DbiGetCursorProps(Ta ble.Handle , Props));
// If the table is a Paradox table, you must call DbiDoRestructure...
if Props.szTableType = szPARADOX then
begin
// Blank out the structure...
FillChar(TableDesc, sizeof(TableDesc), 0);
// Get the database handle from the table's cursor handle...
Check(DbiGetObjFromObj(hDB IObj(Table .Handle), objDATABASE, hDBIObj(hDb)));
// Put the table name in the table descriptor...
StrPCopy(TableDesc.szTblNa me, Table.TableName);
// Put the table type in the table descriptor...
StrPCopy(TableDesc.szTblTy pe, Props.szTableType);
// Set the Pack option in the table descriptor to TRUE...
TableDesc.bPack := True;
// Close the table so the restructure can complete...
Table.Close;
// Call DbiDoRestructure...
Check(DbiDoRestructure(hDb , 1, @TableDesc, nil, nil, nil, FALSE));
end
else
// If the table is a dBASE table, simply call DbiPackTable...
if Props.szTableType = szDBASE then
Check(DbiPackTable(Table.D BHandle, Table.Handle, nil, szDBASE, TRUE))
else
// Pack only works on PAradox or dBASE; nothing else...
raise EDatabaseError.Create('Tab le must be either of Paradox or dBASE ' + 'type to pack');
Table.Open;
end;
end.
Regards
Darren
you could also call the BDE directly. Below is a block of code that was given to me as an answer on E-E for compacting dBase and Paradox tables. There's a bit in it that uses the BDE to re-index and re-structure the tables. Maybe this is of some use.
unit DBPack;
interface
uses BDE, DBTables, DB, sysutils;
procedure PackTable(Table: TTable);
implementation
// This example will pack a Paradox or dBASE table therfore removing already deleted rows in a table.
// This function will also regenerate all out-of-date indexes (maintained indexes).
// This example uses the following input:
// PackTable(Table1)
// The function is defined as follows:
// Pack a Paradox or dBASE table
// The table must be opened execlusively before calling this function...
procedure PackTable(Table: TTable);
var
Props: CURProps;
hDb: hDBIDb;
TableDesc: CRTblDesc;
begin
// Make sure the table is open exclusively so we can get the db handle...
if Table.Active = False then raise EDatabaseError.Create('Tab
if Table.Exclusive = False then raise EDatabaseError.Create('Tab
// Get the table properties to determine table type...
Check(DbiGetCursorProps(Ta
// If the table is a Paradox table, you must call DbiDoRestructure...
if Props.szTableType = szPARADOX then
begin
// Blank out the structure...
FillChar(TableDesc, sizeof(TableDesc), 0);
// Get the database handle from the table's cursor handle...
Check(DbiGetObjFromObj(hDB
// Put the table name in the table descriptor...
StrPCopy(TableDesc.szTblNa
// Put the table type in the table descriptor...
StrPCopy(TableDesc.szTblTy
// Set the Pack option in the table descriptor to TRUE...
TableDesc.bPack := True;
// Close the table so the restructure can complete...
Table.Close;
// Call DbiDoRestructure...
Check(DbiDoRestructure(hDb
end
else
// If the table is a dBASE table, simply call DbiPackTable...
if Props.szTableType = szDBASE then
Check(DbiPackTable(Table.D
else
// Pack only works on PAradox or dBASE; nothing else...
raise EDatabaseError.Create('Tab
Table.Open;
end;
end.
Regards
Darren
See http://www.inprise.com/devsupport/bde/bdeapiex, index secction of BDE functions.