ADO Database Delphi

Create a table with a different level, block size, and fill factor than specified in the BDE configuration. Most Delphi users should use TTable.CreateTable. This example uses the following input:
fDbiCreateTable(Database1.Handle, 'TableChange', 3, @FDesc, 7, 32768, 95);
procedure fDbiCreateTable(hTmpDb: hDBIDb; TableName: string; Fields: Word;
pFlds: pFLDDesc; Level, BlockSize, FillFactor: Word);
var
pOptDesc, pOrigDesc: pFLDDesc;
pOptData, pOrigData: pBYTE;
TblDesc: CRTblDesc;
sLevel, sBlockSize, sFillFactor: string;
begin
pOptDesc := AllocMem(3 * sizeof(FLDDesc));
pOrigDesc := pOptDesc;
pOptData := AllocMem(20);
pOrigData := pOptData;
try
sLevel := IntToStr(Level);
sBlockSize := IntToStr(BlockSize);
sFillFactor := IntToStr(FIllFactor);
// Set up first parameter
pOptDesc.iOffset := 0;
pOptDesc.iLen := Length(sLevel) + 1;
StrPCopy(pOptDesc.szName, 'LEVEL');
StrPCopy(PChar(pOptData), sLevel);
Inc(pOptData, Length(sLevel) + 1);
Inc(pOptDesc);
// Set up second parameter
pOptDesc.iOffset := Length(sLevel) + 1;
pOptDesc.iLen := Length(sLevel) + 1 + Length(sBlockSize) + 1;
StrPCopy(pOptDesc.szName, 'BLOCK SIZE');
StrPCopy(PChar(pOptData), sBLockSize);
Inc(pOptData, Length(sBlockSize) + 1);
Inc(pOptDesc);
// Set up third parameter
pOptDesc.iOffset := Length(sLevel) + 1 + Length(sBlockSize) + 1;
pOptDesc.iLen := Length(sLevel) + 1 + Length(sBlockSize) + 1 +
Length(sFillFactor) + 1;
StrPCopy(pOptDesc.szName, 'FILL FACTOR');
StrPCopy(PChar(pOptData), sFillFactor);
// Format the table descriptor
FillChar(TblDesc, sizeof(TblDesc), #0);
StrPCopy(TblDesc.szTblName, TableName);
StrCopy(TblDesc.szTblType, szPARADOX);
TblDesc.iOptParams := 3;
TblDesc.pFldOptParams := pOrigDesc;
TblDesc.pOptData := pOrigData;
TblDesc.iFldCount := Fields;
TblDesc.pFldDesc := pFlds;
// Create the table
Check(DbiCreateTable(hTmpDb, True, TblDesc));
finally
FreeMem(pOrigDesc, 3 * sizeof(FLDDesc));
FreeMem(pOrigData, 20);
end;
end;
//**********************************************************************************
Create a temporary table using BDE logical types in the field descriptor.
Note: This table can be made permanent later on.
procedure fDbiCreateTempTable(var hTmpDb: hDBIDb;var hTmpCur: hDBICur);
const
fldDes: array[0..1] of FLDDesc = (
( // Field 1 - ALPHA
iFldNum: 1; { Field Number }
szName: 'MyAlpha'; { Field Name }
iFldType: fldZSTRING; { Field Type }
iSubType: fldUNKNOWN; { Field Subtype }
iUnits1: 10; { Field Size }
iUnits2: 0;
iOffset: 0;
iLen: 0;
iNullOffset: 0;
efldvVchk: fldvNOCHECKS;
efldrRights: fldrREADWRITE
),
( // FIELD 2 - NUMERIC
iFldNum: 2;
szName: 'MyNumber';
iFldType: fldFLOAT;
iSubType: fldUNKNOWN;
iUnits1: 0;
iUnits2: 0;
iOffset: 0;
iLen: 0;
iNullOffset: 0;
efldvVchk: fldvNOCHECKS;
efldrRights: fldrREADWRITE
)
);
var
szTblName: array[0..DBIMAXTBLNAMELEN] of Char;
TblDesc: CRTblDesc; // Create Table Descriptor
NumFields: LongInt;
begin
StrPCopy(szTblName,'TempPXTbl');
NumFields:= 2;
FillChar(TblDesc,sizeof(CRTblDesc),#0);
StrCopy(TblDesc.szTblName, szTblName);
StrCopy(TblDesc.szTblType, szPARADOX);
TblDesc.iFldCount:= NumFields;
TblDesc.pfldDesc:= @fldDes;
//Could add indexes, validity checks, and security descriptors here.
Check(DbiCreateTempTable(hTmpDb, TblDesc, hTmpCur));
end;
Example 2: Create a temporary table using dBASE physical types in the field descriptor.
Note: This table can be made permanent later on.
procedure fDbiCreateTempTable(hTmpDb: hDBIDb;hTmpCur: hDBICur);
const
fldDes: array[0..1] of FLDDesc = (
( // Field 1 - MEMO
iFldNum: 1; { Field Number }
szName: 'MyAlpha'; { Field Name }
iFldType: fldDBMEMO; { Field Type }
iSubType: fldUNKNOWN; { Field Subtype }
iUnits1: 0; { Field Size }
iUnits2: 0;
iOffset: 0;
iLen: 0;
iNullOffset: 0;
efldvVchk: fldvNOCHECKS;
efldrRights: fldrREADWRITE
),
( // FIELD 2 - BOOLEAN
iFldNum: 2; { Field Number }
szName: 'MyNumber'; { Field Name }
iFldType: fldDBBOOL; { Field Type }
iSubType: fldUNKNOWN; { Field Subtype }
iUnits1: 0; { Field Size }
iUnits2: 0;
iOffset: 0;
iLen: 0;
iNullOffset: 0;
efldvVchk: fldvNOCHECKS;
efldrRights: fldrREADWRITE)
);
var
szTblName: array[0..DBIMAXTBLNAMELEN] of Char;
TblDes: CRTblDesc; // Create Table Descriptor
NumFields: LongInt;
begin
StrCopy(szTblName,'TempdBASETbl');
NumFields:= 2;
FillChar(TblDes,SizeOf(TblDes),#0);
StrCopy(TblDes.szTblName, szTblName);
StrCopy(TblDes.szTblType, szDBASE);
TblDes.iFldCount := NumFields;
TblDes.pfldDesc := @fldDes;
//Could add indexes, validity checks, and security descriptors here.
Check(DbiCreateTempTable(hTmpDb, TblDes, hTmpCur));
end;
//********************************************************************************
Decode a DBIDATE structure into month, day, and year numbers.
DbiDateDecode returns a string containing the date. Keep in mind that you need to use this function only when you are directly accessing BDE format dates. Otherwise, VCL handles this conversion for you.
This example uses the following input:
fDbiDateDecode(MyDate, MyMonth, MyDay, MyYear);
The function is defined as:
function fDbiDateDecode(dateD: DbiDATE; var Month: word; var Day: word; var Year: SmallInt): string;
begin
Check(DbiDateDecode(dateD, Month, Day, Year));
Result := Format('%d/%d/%d', [Month, Day, Year]);
end;
//********************************************************************************
Encode month, day, and year numbers into a DBIDATE structure.
Keep in mind that you need to use this function only when you are directly accessing BDE format dates. Otherwise, VCL handles this conversion for you.
This example uses the following input:
fDbiDateEncode(2, 8, 71, MyDate);
The function is defined as:
function fDbiDateEncode(Month : Word, Day : Word, Year : SmallInt, MyDate : DbiDate) : DbiDate;
begin
Check(DbiDateEncode(Month, Day, Year, MyDate));
Result := Mydate;
end;
//*********************************************************************************
Delete an existing index from the configuration file of the current session:
procedure DoDbiDeleteAlias(AliasName: string);
begin
Check(DbiDeleteAlias(nil, PChar(AliasName)));
end;
// Sample input:
DoDbiDeleteAlias('SomeAlias');
//*********************************************************************************
Delete the specified index.
Delphi users should normally call TTable.DeleteIndex rather directly calling dbiDeleteIndex. The method TTable.DeleteIndex is defined as:
procedure DeleteIndex(const Name: string);
The following example removes an alias called "ByCompany" from TTable Table1:
Table1.DeleteIndex('ByCompany');
Delete the active index on a table.
Most Delphi users should use Table.DeleteIndex. This example uses the following input:
fDbiDeleteIndex(CustTemp, False);
The procedure is defined as:
procedure fDbiDeleteIndex(Table: TTable; Tag: Boolean);
var
ActiveIdx: IDXDesc;
begin
if not Table.Exclusive then
raise EDatabaseError.Create('Table must be opened exclusively to delete index');
Check(DbiGetIndexDesc(Table.Handle, 0, ActiveIdx));
// Cannot delete the active index, so change to default
Table.IndexName := '';
Table.IndexFieldNames := '';
Check(DbiDeleteIndex(Table.DBHandle, Table.Handle, nil, nil, ActiveIdx.szName,
ActiveIdx.szTagName, 0));
end;
//********************************************************************************