我用DELPHI 和DBASE 编写的一个程序,在运行过程中遇到如下几个问题:
1. 对于某一条记录,用DELETE 删除后,发现在数据库中只是做了一个删除标志,没有彻底删除。如何彻底删除?
2.查询时,用 IF DM.STUDENT.LOCATE('bh','00001',[]) THEN
BEGIN
EDIT;//此时修改的是bh='00001'记录下面的数据
END;
而DM.STUDENT.LOCATE('bh','00001',[]);修改时才是当前目录的修改
请问这是为什么。
3.运行速度慢,如何创建索引,请举例
谢谢大家的参与!!!

解决方案 »

  1.   

    第一个问题;
    DBIPackTable(Table1.DbHandle, Table1.Handle, 'TABLENAME.DBF', szDBASE, TRUE);
    当然,Table必须用exclusive方式打开!对于Paradox数据库,就麻烦一些了:
    // 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('Table must be opened to pack');
    if Table.Exclusive = False then
    raise EDatabaseError.Create('Table must be opened exclusively to pack');
    // Get the table properties to determine table type...
    Check(DbiGetCursorProps(Table.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(hDBIObj(Table.Handle), objDATABASE, hDBIObj(hDb)));
    // Put the table name in the table descriptor...
    StrPCopy(TableDesc.szTblName, Table.TableName);
    // Put the table type in the table descriptor...
    StrPCopy(TableDesc.szTblType, 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.DBHandle, Table.Handle, nil, szDBASE, TRUE))
    else
    // Pack only works on PAradox or dBASE; nothing else...
    raise EDatabaseError.Create('Table must be either of Paradox or dBASE ' +
    'type to pack');
    Table.Open;
    end;
    第二个问题:加上[]换成[loCaseInsensitive]试试
    第三个问题:在设计数据库时设计索引字段就行了
      

  2.   

    wuqiu(午秋) ( ) :很感谢你的参与和指教!
    第二个问题即使换成那个也不行,因为在定位查找时已经找到了相应的记录,而修改时却对下一个记录做的修改!!这个问题只须将记录指针往前移一个,就可以了满足修改记录的要求,只是不知道为什么出现那样的问题。
    第三个问题,是在DBASE下的数据库,不知道如何建立索引,以前的程序是用FOXBASE 写的,我发现他们以前也是在程序中创建索引的,在设计数据库时没有创建。我有时可能要对多个字段创建一个索引的(按找不同字段组合查询),我觉得还是在程序中动态创建比较好,我在DELPHI里按照SQL语法创建索引没有成功!
    希望你给出详细的答案!再次谢谢你的参与和指教!