在delphi程式中维护dbf数据库(Maintaining the DBF database in the Delphi program)_第1页
在delphi程式中维护dbf数据库(Maintaining the DBF database in the Delphi program)_第2页
在delphi程式中维护dbf数据库(Maintaining the DBF database in the Delphi program)_第3页
在delphi程式中维护dbf数据库(Maintaining the DBF database in the Delphi program)_第4页
在delphi程式中维护dbf数据库(Maintaining the DBF database in the Delphi program)_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、在delphi程式中维护dbf数据库(Maintaining the DBF database in the Delphi program)Maintaining the DBF database in the Delphi programThe research and development of Delphi easy to use and fast, very much the original use of Foxpro and VisualFoxpro programming programmers to Delphi. due to work or other applicati

2、on system, especially the application of the original data, it can not be discarded, and therefore need to use Delphi to maintain the application system of xBase database. This paper summarizes the in the work and learning experience, and the majority of Delphi programmers and enthusiasts to share.I

3、n the following discussion, the main application of the BDE function of.Delphi1.0 BDE function does not provide the help file, see the DelphiDoc in DbiT, DbiP and DbiE three; in Delphi3.0/4.0 can see BDE help file. DBF database operation is discussed in this paper are: real de

4、lete records, delete records, display is to obtain the current record No., set the query matching, recover deleted records.I. delete records reallyIn a Delphi program, using the method of Delete TTable or TQuery component execution delete operation is performed to remove soft, which is equivalent to

5、 Foxpro SetDeleteOff in effect, only will be recorded with an asterisk * marked for deletion, and dont delete the physical database. To really delete, need the Pack Table operation.In the Delphi program, you really need to call the BDE function when you really delete the record. The function is call

6、ed DbiPackTable, and the function prototype is:FunctionDbiPackTable (hDb:hDBIDb; hCursor: hDBICur; pszTableName:PChar; DBIResult; pszDriverType:PChar; bRegenIdxs: Bool);Where: hDb is the handle to the database TDatabse,HCursor is the handle to the data table TTable,PszTableName is the name of the da

7、ta table to delete the record,PszDriverType is the type of data table to delete records,BRegenIdxs indicates whether to update the index file automatically after the record is deletedIn the above four parameters, hDb NULL.hCursor, pszTableName pszDriverType, not for NULL, but must provide enough inf

8、ormation to identify the data table file name and type, when the hCursor is not empty, pszTableName and pszDriverType to NULL; when pszTableName is the path and file name of the data table, hCursor and pszDriverType for NULL.It is worth noting that, when deleting records, if Table is implemented, th

9、en Table must be opened in Exclusive=True. Here is a typical exampleFirst, add the uses statement:DbiTypes, DbiProcs, DbiErrs.Pack, a DBF data table, and DbfTable contains information about the data tablesFunctionPackDbf Le (DbfTable:TTable): boolean;VarErrResult:DBIResult;BeginIfnotDbfTable.Exclusi

10、vethenBeginResult:=false;Exit;End;ErrResult:=DbiPackTable (DbfTable.dbHandle, DbfTable.handle, NIL, NIL, true);IferrResult=DBIERR_NONEthenResult:=trueElseResult:=false;End;Two. Displays or does not display soft deleted recordsWhen the DBF records in the database is soft after deletion, the default i

11、s not seen these records in the TDBGrid database component. We can use the BDE function to control whether the display is soft DBF delete records in the database, as in the Foxpro SetDeleteON/OFF statement.The name of the function to be used is DbiSetProp, and the function prototype is:FunctionDbiSe

12、tProp (hObj: hDBIObj; iProp:Longint; iPropValue:Longint): DBIResult;This function sets the value of an attribute in the DBI objectWhere: hObj is the name of the DBI object, and here we are the handle to the data table TTable;IProp is the property name, and we are using the soft deletion property cur

13、SOFTDELETEON;IPropValue is an attribute value, and we use True or False to indicate whether the soft deletion record is displayedHere is a typical example. Also, add the uses statementDbiTypes, DbiProcs, DbiErrs.FunctionSetDbfDelete (DbfTable:TTable; DeleteOn:boolean): boolean;VarErrResult:DBIResult

14、;BeginResult:=false;If (notDbfTable.active) thenExit;ErrResult:=DbiSetProp (hDBIObj (DbfTable.Handle), curSOFTDELETEON, LongInt (DeleteOn);IferrResult=DBIERR_NONEthenno error, operation succeededBeginResult:=true;DbfTable.refresh;End;End;Three. Get the current record numberWhen using Foxpro, the Rec

15、No () function is used, and the Delphi program doesnt feel like this without the function. Here we can use the BDE function to get the record number of the current record in the data setThe name of the function to be used is DbiGetRecord, and the function prototype is:FunctionDbiGetRecord (hCursor:

16、hDBICur; eLock:DBILockType; pRecBuff:Pointer; precProps: pRECProps): DBIResult;This function is used to obtain some attributes of the current recordWhere: hCursor is the Handle of the data set,ELock is the type of record lock,PRecBuff buffer where records are stored,PrecProps is the record property

17、setHere is a typical example. Also, add the uses statement:DbiTypes, DbiProcs, DbiErrs.FunctionRecNo (ADbfTable:TTable): LongInt;VarRecordProps:RecProps;BeginResult:=0;WithADbfTabledoBeginIfnot activethenExit; make the current record of the dataset consistent with the actual current recordUpdateCurs

18、orPos;IfDBIERR_NONE$#60; DbiGetRecord (Handle, dbiNOLOCK, nil, RecordProps) thenExit;Result:=RecordProps.iPhyRecNum;End;End;Four. Set query matching (exact matching / inexact matching)The use of Foxpro, Set and ExactON/OFF have great effect on query data. In Delphi, we can also conduct such settings

19、. To use the function called DbiSetProp, this time with the property name: iProp curINEXACTON, iPropValue True or False attribute value, says True SetExactOFF.Here is a typical exampleAgain, add the uses statement:DbiTypes, DbiProcs, DbiErrs.FunctionSetDbfExact (DbfTable:TTable; ExactOn:boolean): boolean;VarErrResult:DBIResult;BeginIf (notDbfTable.active) thenBeginResult:=false;Exit;End;ErrResult:=DbiSetProp (hDBIObj (DbfTable.Handle), curINEXACTON, LongInt (notExactOn);IferrResult=DBIERR_NONEthenResult:=trueElseResult:=false;End;Five. Recover records that have b

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论