CPDBSTD4PP.pas
Un article de Wikipedia.
{***************************************************************************** * CPDBSTD.pas * CPDBSTD library * (c) 2002 CPDB.NET * (C) 2002 Laurent Duveau (http://www.aldweb.com), Pascal syntax for HSPascal (http://HSPascal.Fihl.net) * CPDBSTD4PP.pas * (c) 2003 Philippe Charrière (http://www.palmipod.com), Pascal syntax for PP (http://ppcompiler.free.fr) * For more information about this powerfull and free library : http://cpdb.net ****************************************************************************} //-------------------------------------------------------------------- // Define Library Trap Numbers //-------------------------------------------------------------------- const sysLibTrapBase = $A800; const sysLibTrapName = sysLibTrapBase; sysLibTrapOpen = $A801; sysLibTrapClose = $A802; sysLibTrapSleep = $A803; sysLibTrapWake = $A804; sysLibTrapCustom = $A805; sysFileTLibrary = $6C696272; // 'libr' sysTrapSysLibRemove = $A0B8; sysTrapSysLibFind = $A0BA; sysTrapSysLibLoad = $A2AC; sysErrorClass = $0500; sysInvalidRefNum = $FFFF; sysErrParamErr = sysErrorClass or 2; sysErrLibNotFound = sysErrorClass or 10; appErrorClass = $8000; // Application-defined errors errNone = $0000; // No error ErrOKAlert = 10021; // Error Alert with just an OK button // PalmOS libraries API function SysLibRemove(refnum:UInt16):Err;inline(SYSTRAP,sysTrapSysLibRemove); function SysLibFind(const name:string;var refnum:UInt16):Err;inline(SYSTRAP,sysTrapSysLibFind); function SysLibLoad(libType,libCreator:UInt32;var refnum:UInt16):Err;inline(SYSTRAP,sysTrapSysLibLoad); //function SysLibTrapOpen(refnum,version:UInt16):Err;inline(SYSTRAP,sysLibTrapOpen); //function SysLibTrapClose(refnum:UInt16;var usecount:UInt16):Err;inline(SYSTRAP,sysLibTrapClose); var CPDB_REFNUM: UInt16; CPDB_CLIENTCONTEXT: UInt32; const //* Error codes */ CPDB_ERR_INVALID = 1; CPDB_ERR_OVERFLOW = 2; CPDB_ERR_OPENFAILED = 3; CPDB_ERR_READFAILED = 4; CPDB_ERR_WRITEFAILED = 5; CPDB_ERR_NOPREVREAD = 6; CPDB_ERR_BOF = 7; CPDB_ERR_EOF = 8; CPDB_ERR_TYPEMISMATCH = 9; CPDB_ERR_NOEXIST = 10; CPDB_ERR_INVALIDDATABASENAME = 1001; CPDB_ERR_DATABASEALREADYEXIST = 1002; CPDB_ERR_CARDNOTPRESENT = 1003; CPDB_ERR_MEMORYERROR = 1004; CPDB_ERR_CHUNKLOCKED = 1005; CPDB_ERR_INVALIDPARAM = 1006; CPDB_ERR_INVALIDSTOREHEADER = 1007; CPDB_ERR_NOTENOUGHSPACE = 1008; CPDB_ERR_RAMONLYCARD = 1009; CPDB_ERR_BADLIBSTATE = 9999; //* Find modes */ CPDB_FIND_REVERSE = 1; CPDB_FIND_FROMCURRENT = 2; CPDB_FIND_WITHIN = 4; CPDB_FIND_CASELESS = 8; CPDB_FIND_UNTIL = 16; //* Sort modes */ CPDB_SORT_ASC = 0; CPDB_SORT_DESC = 1; //* Types */ // Types numeric representation type cpdb_TypeRubrique = ( CPDB_TYPECHAINE = 0, CPDB_TYPEENTIERCOURT = 1, CPDB_TYPEENTIER = 2, CPDB_TYPEENTIERLONG = 3, CPDB_TYPEINCONNU = $FF ); cpdb_FieldType = ( CPDB_TYPESTRING = 0, CPDB_TYPESHORTINT = 1, CPDB_TYPEINT = 2, CPDB_TYPELONGINT = 3, CPDB_TYPEUNKNOWN = $FF ); // Types string reprentation (english only) // Use this constants for database mask description // (see CPDB_CreateDatabase) const CPDB_STYPESTRING = 'STRING'; CPDB_STYPESHORTINT = 'SHORTINT'; CPDB_STYPEINT = 'INT'; CPDB_STYPELONGINT = 'LONGINT'; //* Limits */ // Size of the field name CPDB_MAX_FIELDNAMESIZE = 30; // Size of the description string of a database (see CPDB_CreateDatabase) CPDB_MAX_DATABASEDESCRIPTIONSIZE = 255; // Number of field allowed in a database CPDB_MAX_NBFIELD = 100; {********************************************************************* * Type and creator of Sample Library database *********************************************************************} //CPDBSTDCreatorID = 'CPDB'; CPDBSTDCreatorID= $43504442; // 'CPDB' CPDBSTDTypeID = sysFileTLibrary; {********************************************************************* * Internal library name which can be passed to SysLibFind() *********************************************************************} CPDBSTDName = 'CPDBSTD120'; {********************************************************************* * CPDBSTD result codes * (appErrorClass is reserved for 3rd party apps/libraries. * It is defined in SystemMgr.h) *********************************************************************} //* invalid parameter */ CPDBSTDErrParam = appErrorClass or 1; //* library is not open */ CPDBSTDErrNotOpen = appErrorClass or 2; //* returned from CPDBSTDClose() if the library is still open */ CPDBSTDErrStillOpen = appErrorClass or 3; //* Standard library open, close, sleep and wake functions */ Function CPDBSTDOpen(refNum:UInt16;var clientContextP:UInt32):Err; inline(SYSTRAP,sysLibTrapOpen); Function CPDBSTDClose(refNum:UInt16;clientContext:UInt32):Err; inline(SYSTRAP,sysLibTrapClose); Function CPDBSTDSleep(refNum:UInt16):Err; inline(SYSTRAP,sysLibTrapSleep); Function CPDBSTDWake(refNum:UInt16):Err; inline(SYSTRAP,sysLibTrapWake); //* Custom library API functions */ Function CPDB_CALL_Open(refNum:UInt16;clientContext:UInt32;pcardNo:UInt16;const pnameP:String;pmode:UInt16;var piHandle:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 5); Function CPDB_CALL_Close(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 6); Function CPDB_CALL_ReadFirst(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 7); Function CPDB_CALL_ReadNext(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 8); Function CPDB_CALL_ReadPrevious(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 9); Function CPDB_CALL_ReadLast(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 10); Function CPDB_CALL_SeekForward(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;iOffset:UInt16):Err; inline(SYSTRAP,sysLibTrapBase + 11); Function CPDB_CALL_SeekBackWard(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;iOffset:UInt16):Err; inline(SYSTRAP,sysLibTrapBase + 12); Function CPDB_CALL_IsOut(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;var piFlag:Boolean):Err; inline(SYSTRAP,sysLibTrapBase + 13); Function CPDB_CALL_IsFound(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;var piFlag:Boolean):Err; inline(SYSTRAP,sysLibTrapBase + 14); Function CPDB_CALL_ReadShortInt(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;var piValue:Int8):Err; inline(SYSTRAP,sysLibTrapBase + 15); Function CPDB_CALL_ReadInt(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;var piValue:Int16):Err; inline(SYSTRAP,sysLibTrapBase + 16); Function CPDB_CALL_ReadLongInt(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;var piValue:Int32):Err; inline(SYSTRAP,sysLibTrapBase + 17); Function CPDB_CALL_ReadString(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sNom:String;var phValue:MemHandle):Err; inline(SYSTRAP,sysLibTrapBase + 18); Function CPDB_CALL_CountRecord(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;var piValue:UInt16):Err; inline(SYSTRAP,sysLibTrapBase + 19); Function CPDB_CALL_FindNumeric(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;iValue:Int32;iMode:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 20); Function CPDB_CALL_Sort(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;iDirection:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 21); Function CPDB_CALL_ListField(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;var phList:MemHandle):Err; inline(SYSTRAP,sysLibTrapBase + 22); Function CPDB_CALL_Find(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;const sValue:String;iMode:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 23); Function CPDB_CALL_SeekDirect(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;iPosition:UInt16):Err; inline(SYSTRAP,sysLibTrapBase + 24); Function CPDB_CALL_ReadPosition(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;var piPosition:Int16):Err; inline(SYSTRAP,sysLibTrapBase + 25); Function CPDB_CALL_ReadVersion(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;var phValue:MemHandle):Err; inline(SYSTRAP,sysLibTrapBase + 26); Function CPDB_CALL_DatabaseExist(refNum:UInt16;clientContext:UInt32;const sName:String):Err; inline(SYSTRAP,sysLibTrapBase + 27); Function CPDB_CALL_CreateDatabase(refNum:UInt16;clientContext:UInt32;iCardNo:UInt16;const sNom:String;iCreator:UInt32;const sDescription:String):Err; inline(SYSTRAP,sysLibTrapBase + 28); Function CPDB_CALL_AddRecord(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 29); Function CPDB_CALL_WriteShortInt(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;iValue:Int8):Err; inline(SYSTRAP,sysLibTrapBase + 30); Function CPDB_CALL_WriteInt(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;iValue:Int16):Err; inline(SYSTRAP,sysLibTrapBase + 31); Function CPDB_CALL_WriteLongInt(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;iValue:Int32):Err; inline(SYSTRAP,sysLibTrapBase + 32); Function CPDB_CALL_WriteString(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;const sValue:String):Err; inline(SYSTRAP,sysLibTrapBase + 33); Function CPDB_CALL_UpdateRecord(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 34); Function CPDB_CALL_DeleteRecord(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 35); Function CPDB_CALL_Clear(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err; inline(SYSTRAP,sysLibTrapBase + 36); //* PP functions calls */ Function CPDB_Ouvrir(pcardNo:UInt16;const pnameP:String;pmode:UInt16;var piHandle:UInt8):Err; begin CPDB_Ouvrir:=CPDB_CALL_Open(CPDB_REFNUM,CPDB_CLIENTCONTEXT,pcardNo,pnameP,pmode,piHandle); end; Function CPDB_Open(pcardNo:UInt16;const pnameP:String;pmode:UInt16;var piHandle:UInt8):Err; begin CPDB_Open:=CPDB_CALL_Open(CPDB_REFNUM,CPDB_CLIENTCONTEXT,pcardNo,pnameP,pmode,piHandle); end; Function CPDB_Fermer(iHandle:UInt8):Err; begin CPDB_Fermer:=CPDB_CALL_Close(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_Close(iHandle:UInt8):Err; begin CPDB_Close:=CPDB_CALL_Close(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_LirePremier(iHandle:UInt8):Err; begin CPDB_LirePremier:=CPDB_CALL_ReadFirst(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_ReadFirst(iHandle:UInt8):Err; begin CPDB_ReadFirst:=CPDB_CALL_ReadFirst(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_LireSuivant(iHandle:UInt8):Err; begin CPDB_LireSuivant:=CPDB_CALL_ReadNext(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_ReadNext(iHandle:UInt8):Err; begin CPDB_ReadNext:=CPDB_CALL_ReadNext(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_LirePrecedent(iHandle:UInt8):Err; begin CPDB_LirePrecedent:=CPDB_CALL_ReadPrevious(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_ReadPrevious(iHandle:UInt8):Err; begin CPDB_ReadPrevious:=CPDB_CALL_ReadPrevious(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_LireDernier(iHandle:UInt8):Err; begin CPDB_LireDernier:=CPDB_CALL_ReadLast(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_ReadLast(iHandle:UInt8):Err; begin CPDB_ReadLast:=CPDB_CALL_ReadLast(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_Avancer(iHandle:UInt8;iOffset:UInt16):Err; begin CPDB_Avancer:=CPDB_CALL_SeekForward(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,iOffset); end; Function CPDB_SeekForward(iHandle:UInt8;iOffset:UInt16):Err; begin CPDB_SeekForward:=CPDB_CALL_SeekForward(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,iOffset); end; Function CPDB_Reculer(iHandle:UInt8;iOffset:UInt16):Err; begin CPDB_Reculer:=CPDB_CALL_SeekBackWard(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,iOffset); end; Function CPDB_SeekBackWard(iHandle:UInt8;iOffset:UInt16):Err; begin CPDB_SeekBackWard:=CPDB_CALL_SeekBackWard(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,iOffset); end; Function CPDB_EstEnDehors(iHandle:UInt8;var piFlag:Boolean):Err; begin CPDB_EstEnDehors:=CPDB_CALL_IsOut(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piFlag); end; Function CPDB_IsOut(iHandle:UInt8;var piFlag:Boolean):Err; begin CPDB_IsOut:=CPDB_CALL_IsOut(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piFlag); end; Function CPDB_EstTrouve(iHandle:UInt8;var piFlag:Boolean):Err; begin CPDB_EstTrouve:=CPDB_CALL_IsFound(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piFlag); end; Function CPDB_IsFound(iHandle:UInt8;var piFlag:Boolean):Err; begin CPDB_IsFound:=CPDB_CALL_IsFound(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piFlag); end; Function CPDB_LireEntierCourt(iHandle:UInt8;const sName:String;var piValue:Int8):Err; begin CPDB_LireEntierCourt:=CPDB_CALL_ReadShortInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,piValue); end; Function CPDB_ReadShortInt(iHandle:UInt8;const sName:String;var piValue:Int8):Err; begin CPDB_ReadShortInt:=CPDB_CALL_ReadShortInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,piValue); end; Function CPDB_LireEntier(iHandle:UInt8;const sName:String;var piValue:Int16):Err; begin CPDB_LireEntier:=CPDB_CALL_ReadInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,piValue); end; Function CPDB_ReadInt(iHandle:UInt8;const sName:String;var piValue:Int16):Err; begin CPDB_ReadInt:=CPDB_CALL_ReadInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,piValue); end; Function CPDB_LireEntierLong(iHandle:UInt8;const sName:String;var piValue:Int32):Err; begin CPDB_LireEntierLong:=CPDB_CALL_ReadLongInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,piValue); end; Function CPDB_ReadLongInt(iHandle:UInt8;const sName:String;var piValue:Int32):Err; begin CPDB_ReadLongInt:=CPDB_CALL_ReadLongInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,piValue); end; Function CPDB_LireChaine(iHandle:UInt8;const sNom:String;var phValue:MemHandle):Err; begin CPDB_LireChaine:=CPDB_CALL_ReadString(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sNom,phValue); end; Function CPDB_ReadString(iHandle:UInt8;const sNom:String;var phValue:MemHandle):Err; begin CPDB_ReadString:=CPDB_CALL_ReadString(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sNom,phValue); end; Function CPDB_CompterEnregistrement(iHandle:UInt8;var piValue:UInt16):Err; begin CPDB_CompterEnregistrement:=CPDB_CALL_CountRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piValue); end; Function CPDB_CountRecord(iHandle:UInt8;var piValue:UInt16):Err; begin CPDB_CountRecord:=CPDB_CALL_CountRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piValue); end; Function CPDB_RechercherNumerique(iHandle:UInt8;const sName:String;iValue:Int32;iMode:UInt8):Err; begin CPDB_RechercherNumerique:=CPDB_CALL_FindNumeric(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue,iMode); end; Function CPDB_FindNumeric(iHandle:UInt8;const sName:String;iValue:Int32;iMode:UInt8):Err; begin CPDB_FindNumeric:=CPDB_CALL_FindNumeric(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue,iMode); end; Function CPDB_Trier(iHandle:UInt8;const sName:String;iDirection:UInt8):Err; begin CPDB_Trier:=CPDB_CALL_Sort(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iDirection); end; Function CPDB_Sort(iHandle:UInt8;const sName:String;iDirection:UInt8):Err; begin CPDB_Sort:=CPDB_CALL_Sort(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iDirection); end; Function CPDB_ListerRubrique(iHandle:UInt8;var phList:MemHandle):Err; begin CPDB_ListerRubrique:=CPDB_CALL_ListField(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,phList); end; Function CPDB_ListField(iHandle:UInt8;var phList:MemHandle):Err; begin CPDB_ListField:=CPDB_CALL_ListField(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,phList); end; Function CPDB_Rechercher(iHandle:UInt8;const sName:String;const sValue:String;iMode:UInt8):Err; begin CPDB_Rechercher:=CPDB_CALL_Find(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,sValue,iMode); end; Function CPDB_Find(iHandle:UInt8;const sName:String;const sValue:String;iMode:UInt8):Err; begin CPDB_Find:=CPDB_CALL_Find(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,sValue,iMode); end; Function CPDB_Positionner(iHandle:UInt8;iPosition:UInt16):Err; begin CPDB_Positionner:=CPDB_CALL_SeekDirect(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,iPosition); end; Function CPDB_SeekDirect(iHandle:UInt8;iPosition:UInt16):Err; begin CPDB_SeekDirect:=CPDB_CALL_SeekDirect(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,iPosition); end; Function CPDB_LirePosition(iHandle:UInt8;var piPosition:Int16):Err; begin CPDB_LirePosition:=CPDB_CALL_ReadPosition(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piPosition); end; Function CPDB_ReadPosition(iHandle:UInt8;var piPosition:Int16):Err; begin CPDB_ReadPosition:=CPDB_CALL_ReadPosition(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piPosition); end; Function CPDB_LireVersion(iHandle:UInt8;var phValue:MemHandle):Err; begin CPDB_LireVersion:=CPDB_CALL_ReadVersion(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,phValue); end; Function CPDB_ReadVersion(iHandle:UInt8;var phValue:MemHandle):Err; begin CPDB_ReadVersion:=CPDB_CALL_ReadVersion(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,phValue); end; Function CPDB_DatabaseExiste(const sName:String):Err; begin CPDB_DatabaseExiste:=CPDB_CALL_DatabaseExist(CPDB_REFNUM,CPDB_CLIENTCONTEXT,sName); end; Function CPDB_DatabaseExist(const sName:String):Err; begin CPDB_DatabaseExist:=CPDB_CALL_DatabaseExist(CPDB_REFNUM,CPDB_CLIENTCONTEXT,sName); end; Function CPDB_CreerDatabase(iCardNo:UInt16;const sNom:String;iCreator:UInt32;const sDescription:String):Err; begin CPDB_CreerDatabase:=CPDB_CALL_CreateDatabase(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iCardNo,sNom,iCreator,sDescription); end; Function CPDB_CreateDatabase(iCardNo:UInt16;const sNom:String;iCreator:UInt32;const sDescription:String):Err; begin CPDB_CreateDatabase:=CPDB_CALL_CreateDatabase(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iCardNo,sNom,iCreator,sDescription); end; Function CPDB_AjouteEnregistrement(iHandle:UInt8):Err; begin CPDB_AjouteEnregistrement:=CPDB_CALL_AddRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_AddRecord(iHandle:UInt8):Err; begin CPDB_AddRecord:=CPDB_CALL_AddRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_EcrireEntierCourt(iHandle:UInt8;const sName:String;iValue:Int8):Err; begin CPDB_EcrireEntierCourt:=CPDB_CALL_WriteShortInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue); end; Function CPDB_WriteShortInt(iHandle:UInt8;const sName:String;iValue:Int8):Err; begin CPDB_WriteShortInt:=CPDB_CALL_WriteShortInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue); end; Function CPDB_EcrireEntier(iHandle:UInt8;const sName:String;iValue:Int16):Err; begin CPDB_EcrireEntier:=CPDB_CALL_WriteInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue); end; Function CPDB_WriteInt(iHandle:UInt8;const sName:String;iValue:Int16):Err; begin CPDB_WriteInt:=CPDB_CALL_WriteInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue); end; Function CPDB_EcrireEntierLong(iHandle:UInt8;const sName:String;iValue:Int32):Err; begin CPDB_EcrireEntierLong:=CPDB_CALL_WriteLongInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue); end; Function CPDB_WriteLongInt(iHandle:UInt8;const sName:String;iValue:Int32):Err; begin CPDB_WriteLongInt:=CPDB_CALL_WriteLongInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue); end; Function CPDB_EcrireChaine(iHandle:UInt8;const sName:String;const sValue:String):Err; begin CPDB_EcrireChaine:=CPDB_CALL_WriteString(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,sValue); end; Function CPDB_WriteString(iHandle:UInt8;const sName:String;const sValue:String):Err; begin CPDB_WriteString:=CPDB_CALL_WriteString(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,sValue); end; Function CPDB_MettreAJourEnregistrement(iHandle:UInt8):Err; begin CPDB_MettreAJourEnregistrement:=CPDB_CALL_UpdateRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_UpdateRecord(iHandle:UInt8):Err; begin CPDB_UpdateRecord:=CPDB_CALL_UpdateRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_SupprimerEnregistrement(iHandle:UInt8):Err; begin CPDB_SupprimerEnregistrement:=CPDB_CALL_DeleteRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_DeleteRecord(iHandle:UInt8):Err; begin CPDB_DeleteRecord:=CPDB_CALL_DeleteRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_RAZ(iHandle:UInt8):Err; begin CPDB_RAZ:=CPDB_CALL_Clear(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; Function CPDB_Clear(iHandle:UInt8):Err; begin CPDB_Clear:=CPDB_CALL_Clear(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle); end; {* * FUNCTION: CPDBSTD_CloseLibrary * * DESCRIPTION: * * User-level call to closes the shared library. This handles removal * of the library from system if there are no users remaining. * * PARAMETERS: * * refNum * Library reference number obtained from CPDBSTD_OpenLibrary(). * * clientContext * client context (as returned by the open call) * * CALLED BY: Whoever wants to close the library * * RETURNS: * errNone * sysErrParamErr *} Function CPDBSTD_CloseLibrary(refNum:UInt16;clientContext:UInt32):Err; label 99; var Error,rc:Err; begin if refNum=sysInvalidRefNum then begin CPDBSTD_CloseLibrary:=sysErrParamErr; //exit; goto 99; end; Error:=CPDBSTDClose(refNum,clientContext); if Error=errNone then rc:=sysLibRemove(refNum) else if Error=CPDBSTDErrStillOpen then Error:=errNone; CPDBSTD_CloseLibrary:=Error; 99: end; {* * FUNCTION: CPDBSTD_OpenLibrary * * DESCRIPTION: * * User-level call to open the library. This inline function * handles the messy task of finding or loading the library * and calling its open function; including handling cleanup * if the library could not be opened. * * PARAMETERS: * * refNumP * Pointer to UInt16 variable that will hold the new * library reference number for use in later calls * * clientContextP * pointer to variable for returning client context. The client context is * used to maintain client-specific data for multiple client support. The * value returned here will be used as a parameter for other library * functions which require a client context. * * CALLED BY: System * * RETURNS: * errNone * memErrNotEnoughSpace * sysErrLibNotFound * sysErrNoFreeRAM * sysErrNoFreeLibSlots * * SIDE EFFECTS: * *clientContextP will be set to client context on success, or zero on * error. *} Function CPDBSTD_OpenLibrary(var refNumP:UInt16;var clientContextP:UInt32):Err; var Error,rc:Err; Loaded:Boolean; begin Loaded:=false; Error:=sysLibFind(CPDBSTDName,refNumP); if Error=sysErrLibNotFound then begin Error:=sysLibLoad(CPDBSTDTypeID,CPDBSTDCreatorID,refNumP); Loaded:=true; end; if Error=errNone then begin Error:=CPDBSTDOpen(refNumP,clientContextP); if Error<>errNone then begin if Loaded then rc:=sysLibRemove(refNumP); refNumP:=sysInvalidRefNum; end; end; CPDBSTD_OpenLibrary:=Error; end; Procedure ErrDisplay(Msg:string); type PChar = StringPtr; function ErrAlertCustom(errCode: Err; errMsgP, preMsgP, postMsgP: PChar): UInt16; inline(SYSTRAP,$A365); var ErrAlert:UInt16; begin ErrAlert:=ErrAlertCustom(ErrOKAlert,@msg,nil,nil); end; {********************************************************************* * Macros for open & close lib *********************************************************************} Procedure CPDB_OPENLIB; var Error:Err; begin Error:=CPDBSTD_OpenLibrary(CPDB_REFNUM,CPDB_CLIENTCONTEXT); if Error<>errNone then ErrDisplay('Unable to open CPDB'); end; Procedure CPDB_CLOSELIB; var Error:Err; begin Error:=CPDBSTD_CloseLibrary(CPDB_REFNUM,CPDB_CLIENTCONTEXT); if Error<>errNone then ErrDisplay('Unable to close CPDB'); end;
Catégories: Source | Logiciel | Pascal | Palm