<HTML>
<HEAD>
<TITLE>BDE API Examples (DbiDoRestructurex)</TITLE>
<META NAME="KEYWORDS" CONTENT="BDE, Borland">
<META NAME="DESCRIPTION" CONTENT="">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#000000" ALINK="#999999" VLINK="#666666">
<CENTER>
<TABLE CELLPADDING="4" CELLSPACING="4" BORDER="0" WIDTH="600">
<TR>
<TD ALIGN="CENTER" VALIGN="TOP" COLSPAN="1"><NOBR><A HREF="/"><IMG SRC="/images/bolus.gif" ALT="[View Borland Home Page]" BORDER="0"></A><A HREF="/products.html"><IMG SRC="/images/products.gif" ALT="[View Product List]" BORDER="0"></A><A HREF="/searchsite/"><IMG SRC="/images/search.gif" ALT="[Search This Web Site]" BORDER="0"></A><A HREF="/download.html"><IMG SRC="/images/downloads.gif" ALT="[View Available Downloads]" BORDER="0"></A><A HREF="/membership.html"><IMG SRC="/images/membership.gif" ALT="[Join Borland Online]" BORDER="0"></A><A HREF="/newsgroups/"><IMG SRC="/images/newsgroups.gif" ALT="[Enter Discussion Area]" BORDER="0"></A><A HREF="/feedback/"><IMG SRC="/images/feedback.gif" ALT="[Send Email To Webmaster]" BORDER="0"></A></NOBR></TD>
</TR>
<TR>
<TR><TD ALIGN="LEFT" VALIGN="TOP" COLSPAN="1"><font size=2>
<h2>BDE API Examples (DbiDoRestructure)</h2>
Changes the properties of a table.
<hr size=2 noshade>
<H3>Example 1: Add a validity check to the specified field.</H3>
The field must be a longint, and the TTable must be open. This example uses
the following input:<BR>
<I>fDbiDoRestructure(Table4, Table4.Fields[0], @Min, @Max, nil, True)</I> NOTE: This input works for the EMPLOYEE.DB table.
<PRE>procedure fDbiDoRestructure(Tbl: TTable; Field: TField; MinVal, MaxVal,
DefVal: pLongint; Required: Bool);
var
hDb: hDbiDb;
TblDesc: CRTblDesc;
VChk: pVChkDesc;
Dir: String;
NumVChks: Word;
OpType: CROpType;
begin
NumVChks := 0;
SetLength(Dir, dbiMaxNameLen + 1);
Check(DbiGetDirectory(Tbl.DBHandle, False, PChar(Dir)));
SetLength(Dir, StrLen(PChar(Dir)));
VChk := AllocMem(sizeof(VChkDesc));
try
FillChar(TblDesc, sizeof(CRTblDesc), #0);
VChk.iFldNum := Field.Index + 1;
Tbl.DisableControls;
Tbl.Close;
Check(DbiOpenDatabase(nil, nil, dbiReadWrite, dbiOpenExcl,
nil, 0, nil, nil, hDb));
Check(DbiSetDirectory(hDb, PChar(Dir)));
with VChk^ do
begin
bRequired := Required;
if MinVal <> nil then
begin
Inc(NumVChks);
bHasMinVal := True;
move(MinVal^, aMinVal, sizeof(MinVal^));
end
else
bHasMinVal := False;
if MaxVal <> nil then
begin
Inc(NumVChks);
bHasMaxVal := True;
move(MaxVal^, aMaxVal, sizeof(MaxVal^));
end
else
bHasMaxVal := False;
if DefVal <> nil then
begin
Inc(NumVChks);
bHasDefVal := True;
move(DefVal^, aDefVal, sizeof(DefVal^));
end
else
bHasDefVal := False;
end;
TblDesc.iValChkCount := NumVChks;
TblDesc.pVChkDesc := VChk;
OpType := crADD;
TblDesc.pecrValChkOp := @OpType;
StrPCopy(TblDesc.szTblName, Tbl.TableName);
StrCopy(TblDesc.szTblType, szParadox);
Check(DbiDoRestructure(hDb, 1, @TblDesc, nil, nil, nil, False));
finally
Check(DbiCloseDatabase(hDb));
FreeMem(VChk, sizeof(VChkDesc));
Tbl.EnableControls;
Tbl.Open;
end;
end;</PRE>
<!-- SF -->
<HR SIZE=2 NOSHADE>
<A NAME="Ex2"></A>
<H3>Example 2: Pack a Paradox or dBASE table.</H3>
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:<BR>
<I>PackTable(Table1)</I>
<PRE>// 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;</PRE>
<!-- SF -->
<HR SIZE=2 NOSHADE>
<H3>Example 3: Alter a field in a Paradox or dBASE table.</H3>
This example will alter an existing field in a Paradox or dBASE table.<BR>
NOTE: You must fill in all options in the ChangeRec with 0 or '' if the option is
not used in the restructure. FillChar can be used to do this: Fillchar(MyChangeRec,
sizeof(MyChangeRec), 0);<BR>
This example uses the following input:<BR>
<I>ChangeField(Table1, Table1.FieldByName('FOO'), MyChangeRec)</I><BR>
ChangeRec is defind as follows:
<PRE>ChangeRec = packed record
szName: DBINAME;
iType: word;
iSubType: word;
iLength: word;
iPrecision: byte;
end;</PRE>
The function is defined as follows:
<PRE>procedure ChangeField(Table: TTable; Field: TField; Rec: ChangeRec);
var
Props: CURProps;
hDb: hDBIDb;
TableDesc: CRTblDesc;
pFields: pFLDDesc;
pOp: pCROpType;
B: byte;
begin
// Initialize the pointers...
pFields := nil; pOp := nil;
// 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 restructure');
if Table.Exclusive = False then
raise EDatabaseError.Create('Table must be opened exclusively to restructure');
Check(DbiSetProp(hDBIObj(Table.Handle), curxltMODE, integer(xltNONE)));
// Get the table properties to determine table type...
Check(DbiGetCursorProps(Table.Handle, Props));
// Make sure the table is either Paradox or dBASE...
if (Props.szTableType <> szPARADOX) and (Props.szTableType <> szDBASE) then
raise EDatabaseError.Create('Field altering can only occur on Paradox' +
' or dBASE tables');
// Allocate memory for the field descriptor...
pFields := AllocMem(Table.FieldCount * sizeof(FLDDesc));
// Allocate memory for the operation descriptor...
pOp := AllocMem(Table.FieldCount * sizeof(CROpType));
try
// Set the pointer to the index in the operation descriptor to put
// crMODIFY (This means a modification to the record is going to happen)...
Inc(pOp, Field.Index);
pOp^ := crMODIFY;
Dec(pOp, Field.Index);
// Fill the field descriptor with the existing field information...
Check(DbiGetFieldDescs(Table.Handle, pFields));
// Set the pointer t
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Delphi API使用手册 (105个子文件)
dbidorestructure.html 36KB
dbiopencfginfolist.html 17KB
dbicreatetable.html 10KB
dbiwriteblock.html 8KB
dbiaddindex.html 8KB
dbiopenfieldlist.html 7KB
dbiopenvchklist.html 7KB
dbiopenrintlist.html 5KB
dbiregistercallback.html 5KB
dbigetprop.html 5KB
dbigetsysversion.html 5KB
dbicreatetemptable.html 4KB
dbiisrecordlocked.html 4KB
dbiacqpersisttablelock.html 4KB
dbisorttable.html 4KB
dbiqgetbasedescs.html 4KB
dbiopenldlist.html 4KB
dbiopenuserlist.html 4KB
dbicopytable.html 3KB
dbiopendatabase.html 3KB
dbiopentable.html 3KB
dbiemptytable.html 3KB
dbigeterrorentry.html 3KB
dbireltablelock.html 3KB
dbisetprop.html 3KB
dbisetfieldmap.html 3KB
dbiacqtablelock.html 3KB
dbigetcursorprops.html 3KB
dbiaddalias.html 3KB
dbibeginlinkmode.html 3KB
dbiuseidletime.html 3KB
dbistartsession.html 3KB
dbigetrecord.html 3KB
dbirelrecordlock.html 3KB
dbiqexec.html 3KB
dbiclosesession.html 3KB
dbiopenfieldtypeslist.html 3KB
dbiaddpassword.html 3KB
dbiaddfilter.html 3KB
dbiregenindex.html 3KB
dbipacktable.html 3KB
dbiistablelocked.html 3KB
dbiopendatabaselist.html 3KB
dbigetfielddescs.html 3KB
dbisavechanges.html 3KB
dbireadblock.html 3KB
dbiopentablelist.html 3KB
dbicomparebookmarks.html 3KB
dbiopenfilelist.html 3KB
dbiforcerecordreread.html 3KB
dbigetrecordcount.html 3KB
dbigetldname.html 3KB
dbicheckrefresh.html 3KB
dbigeterrorinfo.html 3KB
dbiopendriverlist.html 3KB
dbigetdatabasedesc.html 3KB
dbiqexecdirect.html 3KB
dbigetclientinfo.html 3KB
dbigetnetusername.html 3KB
dbigetseqno.html 3KB
dbidropfilter.html 3KB
dbiopenindexlist.html 3KB
dbiclonecursor.html 3KB
dbigeterrorcontext.html 3KB
dbiopentabletypeslist.html 3KB
dbiextractkey.html 3KB
dbigetindexforfield.html 3KB
dbideletealias.html 3KB
dbigetindexdesc.html 3KB
dbisettoseqno.html 3KB
dbisetrange.html 3KB
dbisettorecordno.html 3KB
dbiopenlocklist.html 3KB
dbigetldobj.html 3KB
dbiansitonative.html 3KB
dbirelpersisttablelock.html 3KB
dbigetcursorfortable.html 3KB
dbiclosedatabase.html 3KB
dbiforcereread.html 3KB
dbiendlinkmode.html 3KB
dbisettokey.html 3KB
dbisetcurrsession.html 3KB
dbigetcurrsession.html 3KB
dbisetlockretry.html 3KB
dbigettimeformat.html 3KB
dbisettobegin.html 3KB
dbigetnumberformat.html 3KB
dbigetdirectory.html 3KB
dbigetdateformat.html 3KB
dbiregenindexes.html 3KB
dbisettoend.html 3KB
dbiunlinkdetail.html 3KB
dbidebuglayeroptions.html 3KB
dbisetdateformat.html 3KB
dbiformfullname.html 3KB
dbigetsesinfo.html 3KB
dbigetsysconfig.html 3KB
dbigetdriverdesc.html 3KB
dbigetindexdescs.html 3KB
dbigetsysinfo.html 3KB
共 105 条
- 1
- 2
资源评论
- liangyunyou3152012-11-21解压后全是当个的网页文件,英文的,感觉不好
- cohye2015-09-11英文的资料,只有认真研究了。
- CDSN_SB_SYY2015-11-30都不知道这个怎么用,我是菜鸟
javapudding
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功