I'm connecting to old FoxPro 2.6 tables in Delphi 2007.
I've installed the BDE and I put a TTable on the form.One table doesn't work
Set thedatabasename
to c:\datadir
and
The tablename to contacts.dbf
.
When I set active to true, I get
invalid index descriptor.
Another table works fine
I have another table calledarticle.dbf
that loads fine, and in the original program everything works fine as well.
Here's what I've tried
I've already re-indexed everything in the original program, but that makes no difference. In fact the diagno开发者_JAVA技巧stic from Foxpro says that everything is OK. I don't really care about any indexes because there are not that many records in the table. I've tried setting theindexfile
property, but that doesn't help.
How do I get Delphi to just connect to the table and stop complaining about indexes?
Probably your contacts.dbf table contains expression index that cannot be evaluated by BDE. Here is an explanation I have found here
Question: What types of FoxPro indexes are not supported by the BDE? When trying to open some tables, I get an "Invalid Index Descriptor" error.
Answer: This error occurs when the production index (.CDX) associated the table has an index tag which has an expression which the BDE cannot evaluate. The solution is to delete the tag using FoxPro create an eqivalent index that the BDE can understand.
The following conditions are not supported by the BDE and will cause "Invalid Index Descriptor" error.
DTOC(, 1) format not supported; Use DTOC(). ALLTRIM function not supported; Use LTRIM(RTRIM(Field)).
Here's code that Sertac described that will remove the auto-open CDX flag from the header. Make a copy of the dataabase first, of course.
var
Stream: TFileStream;
ByteRead: Byte;
begin
Stream := TFileStream.Create("YourFile.dbf", fmOpenReadWrite or fmShareDenyNone);
try
// Byte offset 28 has a value of 0x01 if a structural (auto-open) index exists,
// or 0x00 if no such index exists. If the value is not set, we do nothing.
Stream.Position := 28;
Stream.Read(ByteRead, SizeOf(ByteRead));
if ByteRead = 1 then
begin
ByteRead := 0;
Stream.Position := 28;
Stream.Write(ByteRead, SizeOf(Byte));
end;
finally
Stream.Free;
end;
end;
精彩评论