📄 dbiaddindex.html
字号:
<HTML>
<HEAD>
<TITLE>BDE API Examples (DbiAddIndex)</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 (DbiAddIndex)</h2>
Creates an index on an existing table.
<hr size=2 noshade>
<p>
<b>Add an index to a Paradox 4.0 or 5.0 version table:
</b><DD>This example is included with Delphi in the BDE32.HLP file.
<p>
<b>Add an index to a Paradox 4.0 or 5.0 version table:
</b><DD>This example is included with Delphi in the BDE32.HLP file.
<p>
<b>Add an index to a Paradox 7.0 version table:
</b><DD>This example is included with Delphi in the BDE32.HLP file.
<p>
<b>Add an index to a dBASE for Windows version table:
</b><DD>This example is included with Delphi in the BDE32.HLP file.
<p>
<b> Add an expression index to a dBASE for Windows version table:
</b><DD>This example is included with Delphi in the BDE32.HLP file.
<hr size=2 noshade>
<h3>Example 1: Create a maintained, case insensitive index on the first and
second fields on a Paradox tables. The first field of the index is
descending and the second is ascending.</h3>
This example uses the following input:<BR> <I>fDbiAddIndex6(Table1)</I>
<PRE>Procedure fDbiAddIndex6(Tbl: TTable);
var
NewIndex: IDXDesc;
begin
FillChar(NewIndex, SizeOf(NewIndex), 0);
if Tbl.Exclusive = False then
raise EDatabaseError.Create
('TTable.Exclusive must be set to true in order to add an index to the table');
NewIndex.szName:= 'NewIndex2';
NewIndex.iIndexId:= 0;
NewIndex.bPrimary:= FALSE;
NewIndex.bUnique:= FALSE;
NewIndex.bDescending:= TRUE;
NewIndex.bMaintained:= TRUE;
NewIndex.bSubset:= FALSE;
NewIndex.bExpIdx:= FALSE;
NewIndex.iFldsInKey:= 2;
NewIndex.aiKeyFld[0]:= 1;
NewIndex.aiKeyFld[1]:=2;
NewIndex.abDescending[0]:=TRUE;
NewIndex.abDescending[1]:=FALSE;
NewIndex.bCaseInsensitive:= TRUE;
Check(DbiAddIndex(Tbl.dbhandle, Tbl.handle, PChar(Tbl.TableName),
szParadox, NewIndex, nil));
end;</PRE>
<!-- QW -->
<hr size=2 noshade>
<h3>Example 2: Create a maintained, expression index with a subset filter.</h3>
This example uses the following input:<BR> <I>AddExpFilter(Table1, 'OUTRISK',
'STR(OUTLOOK)+RISK', 'RISK=''HIGH''');</I><BR>
NOTE: You can use this input with the master.dbf table in the delphi/demos/data directory.
<PRE>procedure AddExpFilter(Table: TTable; TagName, Expression, Filter: string);
var
NewIndex: IDXDesc;
begin
if TagName = '' then
raise EDatabaseError.Create('A tag name must be supplied to create an expression index');
if Expression = '' then
raise EDatabaseError.Create('A expression be supplied to create an index');
if Table.exclusive = False then
raise EDatabaseError.Create('Table: ' + Table.Tablename + ' must be opened exclusively ' +
'to create an index');
FillChar(NewIndex, sizeof(NewIndex), 0);
StrPCopy(NewIndex.szTagName, TagName);
NewIndex.bPrimary:= False;
NewIndex.bUnique:= False;
NewIndex.bDescending:= False;
NewIndex.bMaintained:= True;
if Filter = '' then
NewIndex.bSubset:= False
else
NewIndex.bSubset:= True;
NewIndex.bExpIdx:= True;
StrPCopy(NewIndex.szKeyExp, Expression);
StrPCopy(NewIndex.szKeyCond, Filter);
NewIndex.bCaseInsensitive:= False;
Check(DbiAddIndex(Table.dbhandle, Table.handle, PChar(Table.TableName),
szParadox, NewIndex, nil));
end;</PRE>
<!-- SF, 10/9/97 -->
<hr size=2 noshade>
<h3>Example 3: Create a multi-field secondary index on a Paradox table.</h3>
This example uses the following input:<BR> <I>AddMultiFieldIndex(Table2, 'Multi', False,
[Table2.Fields[0], Table2.Fields[2], Table2.Fields[1]]);</I><BR>
<PRE>procedure AddMultiFieldIndex(Table: TTable; IndexName: string; Unique: boolean;
const Fields: array of TField);
var
NewIndex: IDXDesc;
b: byte;
Props: CURProps;
begin
// Make sure an index name is supplied...
if IndexName = '' then
raise EDatabaseError.Create('An index name must be supplied');
// Make sure the table is opened exclusively...
if Table.exclusive = False then
raise EDatabaseError.Create('Table: ' + Table.Tablename +
' must be opened exclusively to create an index');
Check(DbiGetCursorProps(Table.Handle, Props));
// Make sure the table is of type PARADOX...
if StrComp(Props.szTableType, szPARADOX) <> 0 then
raise EDatabaseError.Create('Table must be of type PARADOX');
FillChar(NewIndex, sizeof(NewIndex), 0);
StrPCopy(NewIndex.szName, IndexName);
NewIndex.bUnique := Unique;
NewIndex.bMaintained := True;
// Set the field mappings for the multi field index...
NewIndex.iFldsInKey := sizeof(Fields) div sizeof(TField);
for b := 0 to NewIndex.iFldsInkey - 1 do
NewIndex.aiKeyFld[b] := Fields[b].Index + 1;
// Create the index...
Check(DbiAddIndex(Table.dbhandle, Table.handle, nil, nil, NewIndex, nil));
end;
</PRE>
<!-- SF, 3/3/98 -->
<hr size=2 noshade>
<p>
<A HREF="/devsupport/bde/bdeapiex/index.html">Back to BDE API Reference Page</A>
</TD></TR>
<TR><TD ALIGN="LEFT" VALIGN="TOP" COLSPAN="1"><font size=2>
<HR SIZE="2" NOSHADE>
<FONT SIZE = 2><i><b>DISCLAIMER:</b> You have the right to use this technical information subject to
the terms of the No-Nonsense License Statement that you received with the Borland product to which
this information pertains.</FONT></i></B>
</dl>
</td>
</TR>
<TR>
<!-- THIS IS THE BOTTOM COPYRIGHT & UPDATED MESSAGE -->
<TD ALIGN="CENTER" VALIGN="TOP" COLSPAN="3"><FONT SIZE="2"><A HREF="/copyright.html">Trademarks & Copyright</A> © 1998 Borland International, Inc.
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM OLD BROWSERS
// THIS WILL WRITE OUT THE LAST MODIFIED DATE
// YOU DO NOT NEED TO CHANGE ANYTHING HERE
function makeArray(arraySize) {
this.length = arraySize
return this
}
monthNames = new makeArray(12)
monthNames[1] = "January"
monthNames[2] = "February"
monthNames[3] = "March"
monthNames[4] = "April"
monthNames[5] = "May"
monthNames[6] = "June"
monthNames[7] = "July"
monthNames[8] = "August"
monthNames[9] = "September"
monthNames[10] = "October"
monthNames[11] = "November"
monthNames[12] = "December"
updated = new Date(document.lastModified)
theMonth = monthNames[updated.getMonth() + 1]
theDate = updated.getDate()
theYear = updated.getYear() + 1900
document.write("Last modified on " + theDate + "-" + theMonth + "-" + theYear + ".")
// END HIDING -->
</SCRIPT></FONT></TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
<html><script language="JavaScript"> </script></html>
<html><script language="JavaScript"> </script></html>
<html><script language="JavaScript"> </script></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -