<< Click to Display Table of Contents >> Navigation: Apollo API Listing > sx_CreateNew |
Declare Function sx_CreateNew Lib "Apollo9.dll"
(ByVal cpFileName As String,
ByVal cpAlias As String,
ByVal iRdeType As Integer,
ByVal iNumFields As Integer)
As Integer
SHORT FAR PASCAL sx_CreateNew
(BYTEP cpFileName,
BYTEP cpAlias,
SHORT iRdeType,
SHORT iNumFields);
Initializes a new work area. This is the first step in creating a new table. The second step is to define each field with iNumFields calls to sx_CreateField. The final step is sx_CreateExec, which physically creates the new table.
Parameters
cpFileName: The DOS name of the new file qualified with a complete path and extension.
cpAlias: The alias name to be assigned to the new file. Every database file opened must be assigned a unique alias name.
iRdeType: Use defined constants:
SDENTX 1 CA-Clipper compatible DBF-NTX driver
SDEFOX 2 FoxPro compatible DBF-IDX/CDX driver
SDENSX 3 Vista DBF-NSX driver
iNumFields: The maximum number of fields to be added to the file structure via calls to sx_CreateField.
The work area number assigned to the database. This number should be retained in a global variable to allow for later selection via sx_Select. The alias name assigned is associated with this work area number.
VB Example
Sub ButtonMake_Click ()
iRet = sx_CreateNew("c:\test\testnew.dbf", "test", SDEFOX, 5)
If iRet = 0 Then
MsgBox "create failed"
Else
sx_CreateField "fchar", "C", 25, 0
sx_CreateField "fnum", "N", 10, 2
sx_CreateField "flog", "L", 1, 0
sx_CreateField "fdate", "D", 8, 0
sx_CreateField "fmemo", "M", 10, 0
If sx_CreateExec() Then
MsgBox "Create succeeded"
sx_Close
Else
MsgBox "create failed"
End If
End If
End Sub
C Example
void CNamesForm::OnInitialUpdate()
{
// do default func first
CFormView::OnInitialUpdate();
// enable float support for VBXs
CVBControl::EnableVBXFloat();
// check if database exists
// and, if not, create
CFileStatus status;
char* pFileName = "names.dbf";
// if CFile status FALSE, create new file
if (!CFile::GetStatus(pFileName, status))
{
sx_CreateNew((BYTEP) "names.dbf", (BYTEP) "name", SDENTX, 5);
sx_CreateField((BYTEP) "name", (BYTEP) "C", 30, 0);
sx_CreateField((BYTEP) "address", (BYTEP) "C", 30, 0);
sx_CreateField((BYTEP) "phone", (BYTEP) "C", 10, 0);
sx_CreateField((BYTEP) "business", (BYTEP) "C", 20, 0);
sx_CreateField((BYTEP) "createdate", (BYTEP) "D", 8, 0);
sx_CreateExec();
sx_Close();
}
}
sx_Alias, sx_CreateExec, sx_CreateField, sx_SetMemoBlockSize, sx_WorkArea