{ format.pas } program Format; {$IfDef VER80} uses SnipTool, SnipData, SysUtils, WinTypes, WinProcs, DbiProcs, DbiTypes, DbiErrs; {$Else} uses WinTypes, WinCrt, Strings, DbiProcs, DbiTypes, DbiErrs, SnipTool, SnipData; {$EndIf} const szTblName = 'FORMAT'; { Name of table to be created. } szTblType = szPARADOX; { Table type to use. } { Field Descriptor used in creating a table } fldDes: array[0..1] of FLDDesc = ( ( { Field 1 - DATE } iFldNum: 1; szName: 'DATE'; iFldType: fldDATE; iSubType: fldUNKNOWN; iUnits1: 0; iUnits2: 0; iOffset: 0; iLen: 0; iNullOffset: 0; efldvVchk: fldvNOCHECKS; efldrRights: fldrREADWRITE ), ( { Field 2 - TIME } iFldNum: 2; szName: 'TIME'; iFldType: fldTIME; iSubType: fldUNKNOWN; iUnits1: 0; iUnits2: 0; iOffset: 0; iLen: 0; iNullOffset: 0; efldvVchk: fldvNOCHECKS; efldrRights: fldrREADWRITE ) ); { Array of field descriptors } {===================================================================== Function: Format(); Description: This example shows how to change the formatting of Date and Time fields. ===================================================================== } var hDb: hDBIDb; { Handle to the database } hCur: hDBICur; { Handle to the table } crTblDes: CRTblDesc; { Create table descriptor } frmtDate: FMTDate; { Date format } frmtTime: FMTTime; { Time format } uNumFields: UINT16; const uDispNumRecs: UINT16 = 10; { Number of records to add and display. } begin Screen('*** Changing the format of Date and Time ***'); Screen(''); Screen(' Initializing IDAPI...'); if (InitAndConnect(hDb) <> DBIERR_NONE) then begin Screen(''); Screen('*** End of Example ***'); exit; end; { The number of fields in the table - note that fldDesc is defined globally } uNumFields := trunc( sizeof(fldDes) / sizeof(fldDes[0]) ); Screen(' Setting the default Database directory...'); ChkRslt(DbiSetDirectory(hDb, pCHAR(szTblDirectory)), DBIERR_NONE, ' Error - SetDirectory.'); Screen(' Initializing the table descriptor...'); FillChar(crTblDes, sizeof(CRTblDesc), #0); StrCopy(crTblDes.szTblName, szTblName); StrCopy(crTblDes.szTblType, szTblType); crTblDes.iFldCount := uNumFields; crTblDes.pfldDesc := @fldDes; Screen(' Creating the "'+szTblName+'" table...'); if (ChkRslt(DbiCreateTable(hDb, TRUE, crTblDes), DBIERR_NONE, ' Error - CreateTable.') <> DBIERR_NONE) then begin Screen(' Close the Database and exit IDAPI...'); CloseDbAndExit(hDb); Screen(''); Screen('*** End of Example ***'); exit; end; Screen(' Fill the table with Random Data...'); FillTable(hDb, pCHAR(szTblName), pCHAR(szTblType), uDispNumRecs); Screen(' Open the "'+szTblName+'" table...'); if (ChkRslt(DbiOpenTable(hDb, pCHAR(szTblName), pCHAR(szTblType), nil, nil, 0, dbiREADWRITE, dbiOPENSHARED, xltFIELD, FALSE, nil, hCur), DBIERR_NONE, ' Error - OpenTable.') <> DBIERR_NONE) then begin Screen(' Close the Database and exit IDAPI...'); CloseDbAndExit(hDb); Screen(''); Screen('*** End of Example ***'); exit; end; Screen(' Display the "'+szTblName+'" table with default date '+ 'and time formats...'); DisplayTable(hCur, uDispNumRecs); { Get the format of the date } ChkRslt(DbiGetDateFormat(frmtDate), DBIERR_NONE, ' Error - GetDateFormat.'); Screen(''); Screen(' Change the Date format: toggle between MM/DD/YY and'+ ' DD/MM/YY...'); if (BYTE(frmtDate.iDateMode) <> 0) then frmtDate.iDateMode := 0 else frmtDate.iDateMode := 1; { Change the format of the date } ChkRslt(DbiSetDateFormat(frmtDate), DBIERR_NONE, ' Error - SetDateFormat.'); { Get the time format } ChkRslt(DbiGetTimeFormat(frmtTime), DBIERR_NONE, ' Error - GetTimeFormat.'); Screen(' Change the Time format: toggle between 12 and 24 hour'+ ' clock...'); if (frmtTime.bTwelveHour) then frmtTime.bTwelveHour := FALSE else frmtTime.bTwelveHour := TRUE; { Change the time format } ChkRslt(DbiSetTimeFormat(frmtTime), DBIERR_NONE, ' Error - SetDateFormat.'); ChkRslt(DbiSetToBegin(hCur), DBIERR_NONE, ' Error - SetToBegin.'); Screen(' Display the "'+szTblName+'" table with the Date and time'+ ' formats changed...'); DisplayTable(hCur, uDispNumRecs); Screen(''); Screen(' Close the "'+szTblName+'" table...'); ChkRslt(DbiCloseCursor(hCur), DBIERR_NONE, ' Error - CloseCursor.'); Screen(' Deleting the "'+szTblName+'" table...'); ChkRslt(DbiDeleteTable(hDb, pCHAR(szTblName), pCHAR(szTblType)), DBIERR_NONE, ' Error - DeleteTable.'); Screen(' Close the Database and exit IDAPI...'); CloseDbAndExit(hDb); Screen(''); Screen('*** End of Example ***'); end.