CPDBSTD4PP.pas

Un article de Wikipedia.

Base de données CPDB

  1. {*****************************************************************************
  2.  * CPDBSTD.pas
  3.  * CPDBSTD library
  4.  * (c) 2002 CPDB.NET
  5.  * (C) 2002 Laurent Duveau (http://www.aldweb.com), Pascal syntax for HSPascal (http://HSPascal.Fihl.net)
  6.  * CPDBSTD4PP.pas
  7.  * (c) 2003 Philippe Charrière (http://www.palmipod.com), Pascal syntax for PP (http://ppcompiler.free.fr)
  8.  * For more information about this powerfull and free library : http://cpdb.net
  9.  ****************************************************************************}
  10.  
  11. //--------------------------------------------------------------------
  12. // Define Library Trap Numbers
  13. //--------------------------------------------------------------------
  14. const
  15. sysLibTrapBase = $A800;
  16.  
  17. const
  18. sysLibTrapName = sysLibTrapBase;
  19. sysLibTrapOpen = $A801;
  20. sysLibTrapClose = $A802;
  21. sysLibTrapSleep = $A803;
  22. sysLibTrapWake = $A804;
  23. sysLibTrapCustom = $A805;
  24.  
  25. sysFileTLibrary = $6C696272; // 'libr'
  26.  
  27. sysTrapSysLibRemove = $A0B8;
  28. sysTrapSysLibFind = $A0BA;
  29. sysTrapSysLibLoad = $A2AC;
  30.  
  31. sysErrorClass = $0500;
  32. sysInvalidRefNum = $FFFF;
  33. sysErrParamErr = sysErrorClass or 2;
  34. sysErrLibNotFound = sysErrorClass or 10;
  35.  
  36.  
  37. appErrorClass = $8000; // Application-defined errors
  38. errNone = $0000; // No error
  39.  
  40. ErrOKAlert = 10021; // Error Alert with just an OK button
  41.  
  42. // PalmOS libraries API
  43.  
  44. function SysLibRemove(refnum:UInt16):Err;inline(SYSTRAP,sysTrapSysLibRemove);
  45. function SysLibFind(const name:string;var refnum:UInt16):Err;inline(SYSTRAP,sysTrapSysLibFind);
  46. function SysLibLoad(libType,libCreator:UInt32;var refnum:UInt16):Err;inline(SYSTRAP,sysTrapSysLibLoad);
  47.  
  48. //function SysLibTrapOpen(refnum,version:UInt16):Err;inline(SYSTRAP,sysLibTrapOpen);
  49. //function SysLibTrapClose(refnum:UInt16;var usecount:UInt16):Err;inline(SYSTRAP,sysLibTrapClose);
  50.  
  51.  
  52.  
  53. var
  54. CPDB_REFNUM: UInt16;
  55. CPDB_CLIENTCONTEXT: UInt32;
  56.  
  57. const
  58.  
  59. //* Error codes */
  60. CPDB_ERR_INVALID = 1;
  61. CPDB_ERR_OVERFLOW = 2;
  62. CPDB_ERR_OPENFAILED = 3;
  63. CPDB_ERR_READFAILED = 4;
  64. CPDB_ERR_WRITEFAILED = 5;
  65. CPDB_ERR_NOPREVREAD = 6;
  66. CPDB_ERR_BOF = 7;
  67. CPDB_ERR_EOF = 8;
  68. CPDB_ERR_TYPEMISMATCH = 9;
  69. CPDB_ERR_NOEXIST = 10;
  70. CPDB_ERR_INVALIDDATABASENAME = 1001;
  71. CPDB_ERR_DATABASEALREADYEXIST = 1002;
  72. CPDB_ERR_CARDNOTPRESENT = 1003;
  73. CPDB_ERR_MEMORYERROR = 1004;
  74. CPDB_ERR_CHUNKLOCKED = 1005;
  75. CPDB_ERR_INVALIDPARAM = 1006;
  76. CPDB_ERR_INVALIDSTOREHEADER = 1007;
  77. CPDB_ERR_NOTENOUGHSPACE = 1008;
  78. CPDB_ERR_RAMONLYCARD = 1009;
  79. CPDB_ERR_BADLIBSTATE = 9999;
  80.  
  81. //* Find modes */
  82. CPDB_FIND_REVERSE = 1;
  83. CPDB_FIND_FROMCURRENT = 2;
  84. CPDB_FIND_WITHIN = 4;
  85. CPDB_FIND_CASELESS = 8;
  86. CPDB_FIND_UNTIL = 16;
  87.  
  88. //* Sort modes */
  89. CPDB_SORT_ASC = 0;
  90. CPDB_SORT_DESC = 1;
  91.  
  92. //* Types */
  93. // Types numeric representation
  94. type
  95. cpdb_TypeRubrique = (
  96. CPDB_TYPECHAINE = 0,
  97. CPDB_TYPEENTIERCOURT = 1,
  98. CPDB_TYPEENTIER = 2,
  99. CPDB_TYPEENTIERLONG = 3,
  100. CPDB_TYPEINCONNU = $FF
  101. );
  102. cpdb_FieldType = (
  103. CPDB_TYPESTRING = 0,
  104. CPDB_TYPESHORTINT = 1,
  105. CPDB_TYPEINT = 2,
  106. CPDB_TYPELONGINT = 3,
  107. CPDB_TYPEUNKNOWN = $FF
  108. );
  109.  
  110. // Types string reprentation (english only)
  111. // Use this constants for database mask description
  112. // (see CPDB_CreateDatabase)
  113. const
  114. CPDB_STYPESTRING = 'STRING';
  115. CPDB_STYPESHORTINT = 'SHORTINT';
  116. CPDB_STYPEINT = 'INT';
  117. CPDB_STYPELONGINT = 'LONGINT';
  118.  
  119.  
  120. //* Limits */
  121. // Size of the field name
  122. CPDB_MAX_FIELDNAMESIZE = 30;
  123. // Size of the description string of a database (see CPDB_CreateDatabase)
  124. CPDB_MAX_DATABASEDESCRIPTIONSIZE = 255;
  125. // Number of field allowed in a database
  126. CPDB_MAX_NBFIELD = 100;
  127.  
  128. {*********************************************************************
  129.  * Type and creator of Sample Library database
  130.  *********************************************************************}
  131.  
  132. //CPDBSTDCreatorID = 'CPDB';
  133. CPDBSTDCreatorID= $43504442; // 'CPDB'
  134. CPDBSTDTypeID = sysFileTLibrary;
  135.  
  136. {*********************************************************************
  137.  * Internal library name which can be passed to SysLibFind()
  138.  *********************************************************************}
  139.  
  140. CPDBSTDName = 'CPDBSTD120';
  141.  
  142. {*********************************************************************
  143.  * CPDBSTD result codes
  144.  * (appErrorClass is reserved for 3rd party apps/libraries.
  145.  * It is defined in SystemMgr.h)
  146.  *********************************************************************}
  147.  
  148. //* invalid parameter */
  149. CPDBSTDErrParam = appErrorClass or 1;
  150.  
  151. //* library is not open */
  152. CPDBSTDErrNotOpen = appErrorClass or 2;
  153.  
  154. //* returned from CPDBSTDClose() if the library is still open */
  155. CPDBSTDErrStillOpen = appErrorClass or 3;
  156.  
  157.  
  158. //* Standard library open, close, sleep and wake functions */
  159.  
  160. Function CPDBSTDOpen(refNum:UInt16;var clientContextP:UInt32):Err;
  161. inline(SYSTRAP,sysLibTrapOpen);
  162.  
  163. Function CPDBSTDClose(refNum:UInt16;clientContext:UInt32):Err;
  164. inline(SYSTRAP,sysLibTrapClose);
  165.  
  166. Function CPDBSTDSleep(refNum:UInt16):Err;
  167. inline(SYSTRAP,sysLibTrapSleep);
  168.  
  169. Function CPDBSTDWake(refNum:UInt16):Err;
  170. inline(SYSTRAP,sysLibTrapWake);
  171.  
  172.  
  173. //* Custom library API functions */
  174.  
  175. Function CPDB_CALL_Open(refNum:UInt16;clientContext:UInt32;pcardNo:UInt16;const pnameP:String;pmode:UInt16;var piHandle:UInt8):Err;
  176. inline(SYSTRAP,sysLibTrapBase + 5);
  177.  
  178. Function CPDB_CALL_Close(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err;
  179. inline(SYSTRAP,sysLibTrapBase + 6);
  180.  
  181. Function CPDB_CALL_ReadFirst(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err;
  182. inline(SYSTRAP,sysLibTrapBase + 7);
  183.  
  184. Function CPDB_CALL_ReadNext(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err;
  185. inline(SYSTRAP,sysLibTrapBase + 8);
  186.  
  187. Function CPDB_CALL_ReadPrevious(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err;
  188. inline(SYSTRAP,sysLibTrapBase + 9);
  189.  
  190. Function CPDB_CALL_ReadLast(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err;
  191. inline(SYSTRAP,sysLibTrapBase + 10);
  192.  
  193. Function CPDB_CALL_SeekForward(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;iOffset:UInt16):Err;
  194. inline(SYSTRAP,sysLibTrapBase + 11);
  195.  
  196. Function CPDB_CALL_SeekBackWard(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;iOffset:UInt16):Err;
  197. inline(SYSTRAP,sysLibTrapBase + 12);
  198.  
  199. Function CPDB_CALL_IsOut(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;var piFlag:Boolean):Err;
  200. inline(SYSTRAP,sysLibTrapBase + 13);
  201.  
  202. Function CPDB_CALL_IsFound(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;var piFlag:Boolean):Err;
  203. inline(SYSTRAP,sysLibTrapBase + 14);
  204.  
  205. Function CPDB_CALL_ReadShortInt(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;var piValue:Int8):Err;
  206. inline(SYSTRAP,sysLibTrapBase + 15);
  207.  
  208. Function CPDB_CALL_ReadInt(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;var piValue:Int16):Err;
  209. inline(SYSTRAP,sysLibTrapBase + 16);
  210.  
  211. Function CPDB_CALL_ReadLongInt(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;var piValue:Int32):Err;
  212. inline(SYSTRAP,sysLibTrapBase + 17);
  213.  
  214. Function CPDB_CALL_ReadString(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sNom:String;var phValue:MemHandle):Err;
  215. inline(SYSTRAP,sysLibTrapBase + 18);
  216.  
  217. Function CPDB_CALL_CountRecord(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;var piValue:UInt16):Err;
  218. inline(SYSTRAP,sysLibTrapBase + 19);
  219.  
  220. Function CPDB_CALL_FindNumeric(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;iValue:Int32;iMode:UInt8):Err;
  221. inline(SYSTRAP,sysLibTrapBase + 20);
  222.  
  223. Function CPDB_CALL_Sort(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;iDirection:UInt8):Err;
  224. inline(SYSTRAP,sysLibTrapBase + 21);
  225.  
  226. Function CPDB_CALL_ListField(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;var phList:MemHandle):Err;
  227. inline(SYSTRAP,sysLibTrapBase + 22);
  228.  
  229. Function CPDB_CALL_Find(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;const sValue:String;iMode:UInt8):Err;
  230. inline(SYSTRAP,sysLibTrapBase + 23);
  231.  
  232. Function CPDB_CALL_SeekDirect(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;iPosition:UInt16):Err;
  233. inline(SYSTRAP,sysLibTrapBase + 24);
  234.  
  235. Function CPDB_CALL_ReadPosition(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;var piPosition:Int16):Err;
  236. inline(SYSTRAP,sysLibTrapBase + 25);
  237.  
  238. Function CPDB_CALL_ReadVersion(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;var phValue:MemHandle):Err;
  239. inline(SYSTRAP,sysLibTrapBase + 26);
  240.  
  241. Function CPDB_CALL_DatabaseExist(refNum:UInt16;clientContext:UInt32;const sName:String):Err;
  242. inline(SYSTRAP,sysLibTrapBase + 27);
  243.  
  244. Function CPDB_CALL_CreateDatabase(refNum:UInt16;clientContext:UInt32;iCardNo:UInt16;const sNom:String;iCreator:UInt32;const sDescription:String):Err;
  245. inline(SYSTRAP,sysLibTrapBase + 28);
  246.  
  247. Function CPDB_CALL_AddRecord(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err;
  248. inline(SYSTRAP,sysLibTrapBase + 29);
  249.  
  250. Function CPDB_CALL_WriteShortInt(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;iValue:Int8):Err;
  251. inline(SYSTRAP,sysLibTrapBase + 30);
  252.  
  253. Function CPDB_CALL_WriteInt(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;iValue:Int16):Err;
  254. inline(SYSTRAP,sysLibTrapBase + 31);
  255.  
  256. Function CPDB_CALL_WriteLongInt(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;iValue:Int32):Err;
  257. inline(SYSTRAP,sysLibTrapBase + 32);
  258.  
  259. Function CPDB_CALL_WriteString(refNum:UInt16;clientContext:UInt32;iHandle:UInt8;const sName:String;const sValue:String):Err;
  260. inline(SYSTRAP,sysLibTrapBase + 33);
  261.  
  262. Function CPDB_CALL_UpdateRecord(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err;
  263. inline(SYSTRAP,sysLibTrapBase + 34);
  264.  
  265. Function CPDB_CALL_DeleteRecord(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err;
  266. inline(SYSTRAP,sysLibTrapBase + 35);
  267.  
  268. Function CPDB_CALL_Clear(refNum:UInt16;clientContext:UInt32;iHandle:UInt8):Err;
  269. inline(SYSTRAP,sysLibTrapBase + 36);
  270.  
  271. //* PP functions calls */
  272.  
  273. Function CPDB_Ouvrir(pcardNo:UInt16;const pnameP:String;pmode:UInt16;var piHandle:UInt8):Err;
  274. begin
  275. CPDB_Ouvrir:=CPDB_CALL_Open(CPDB_REFNUM,CPDB_CLIENTCONTEXT,pcardNo,pnameP,pmode,piHandle);
  276. end;
  277. Function CPDB_Open(pcardNo:UInt16;const pnameP:String;pmode:UInt16;var piHandle:UInt8):Err;
  278. begin
  279. CPDB_Open:=CPDB_CALL_Open(CPDB_REFNUM,CPDB_CLIENTCONTEXT,pcardNo,pnameP,pmode,piHandle);
  280. end;
  281.  
  282. Function CPDB_Fermer(iHandle:UInt8):Err;
  283. begin
  284. CPDB_Fermer:=CPDB_CALL_Close(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  285. end;
  286. Function CPDB_Close(iHandle:UInt8):Err;
  287. begin
  288. CPDB_Close:=CPDB_CALL_Close(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  289. end;
  290.  
  291. Function CPDB_LirePremier(iHandle:UInt8):Err;
  292. begin
  293. CPDB_LirePremier:=CPDB_CALL_ReadFirst(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  294. end;
  295. Function CPDB_ReadFirst(iHandle:UInt8):Err;
  296. begin
  297. CPDB_ReadFirst:=CPDB_CALL_ReadFirst(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  298. end;
  299.  
  300. Function CPDB_LireSuivant(iHandle:UInt8):Err;
  301. begin
  302. CPDB_LireSuivant:=CPDB_CALL_ReadNext(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  303. end;
  304. Function CPDB_ReadNext(iHandle:UInt8):Err;
  305. begin
  306. CPDB_ReadNext:=CPDB_CALL_ReadNext(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  307. end;
  308.  
  309. Function CPDB_LirePrecedent(iHandle:UInt8):Err;
  310. begin
  311. CPDB_LirePrecedent:=CPDB_CALL_ReadPrevious(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  312. end;
  313. Function CPDB_ReadPrevious(iHandle:UInt8):Err;
  314. begin
  315. CPDB_ReadPrevious:=CPDB_CALL_ReadPrevious(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  316. end;
  317.  
  318. Function CPDB_LireDernier(iHandle:UInt8):Err;
  319. begin
  320. CPDB_LireDernier:=CPDB_CALL_ReadLast(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  321. end;
  322. Function CPDB_ReadLast(iHandle:UInt8):Err;
  323. begin
  324. CPDB_ReadLast:=CPDB_CALL_ReadLast(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  325. end;
  326.  
  327. Function CPDB_Avancer(iHandle:UInt8;iOffset:UInt16):Err;
  328. begin
  329. CPDB_Avancer:=CPDB_CALL_SeekForward(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,iOffset);
  330. end;
  331. Function CPDB_SeekForward(iHandle:UInt8;iOffset:UInt16):Err;
  332. begin
  333. CPDB_SeekForward:=CPDB_CALL_SeekForward(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,iOffset);
  334. end;
  335.  
  336. Function CPDB_Reculer(iHandle:UInt8;iOffset:UInt16):Err;
  337. begin
  338. CPDB_Reculer:=CPDB_CALL_SeekBackWard(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,iOffset);
  339. end;
  340. Function CPDB_SeekBackWard(iHandle:UInt8;iOffset:UInt16):Err;
  341. begin
  342. CPDB_SeekBackWard:=CPDB_CALL_SeekBackWard(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,iOffset);
  343. end;
  344.  
  345. Function CPDB_EstEnDehors(iHandle:UInt8;var piFlag:Boolean):Err;
  346. begin
  347. CPDB_EstEnDehors:=CPDB_CALL_IsOut(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piFlag);
  348. end;
  349. Function CPDB_IsOut(iHandle:UInt8;var piFlag:Boolean):Err;
  350. begin
  351. CPDB_IsOut:=CPDB_CALL_IsOut(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piFlag);
  352. end;
  353.  
  354. Function CPDB_EstTrouve(iHandle:UInt8;var piFlag:Boolean):Err;
  355. begin
  356. CPDB_EstTrouve:=CPDB_CALL_IsFound(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piFlag);
  357. end;
  358. Function CPDB_IsFound(iHandle:UInt8;var piFlag:Boolean):Err;
  359. begin
  360. CPDB_IsFound:=CPDB_CALL_IsFound(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piFlag);
  361. end;
  362.  
  363. Function CPDB_LireEntierCourt(iHandle:UInt8;const sName:String;var piValue:Int8):Err;
  364. begin
  365. CPDB_LireEntierCourt:=CPDB_CALL_ReadShortInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,piValue);
  366. end;
  367. Function CPDB_ReadShortInt(iHandle:UInt8;const sName:String;var piValue:Int8):Err;
  368. begin
  369. CPDB_ReadShortInt:=CPDB_CALL_ReadShortInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,piValue);
  370. end;
  371.  
  372. Function CPDB_LireEntier(iHandle:UInt8;const sName:String;var piValue:Int16):Err;
  373. begin
  374. CPDB_LireEntier:=CPDB_CALL_ReadInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,piValue);
  375. end;
  376. Function CPDB_ReadInt(iHandle:UInt8;const sName:String;var piValue:Int16):Err;
  377. begin
  378. CPDB_ReadInt:=CPDB_CALL_ReadInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,piValue);
  379. end;
  380.  
  381. Function CPDB_LireEntierLong(iHandle:UInt8;const sName:String;var piValue:Int32):Err;
  382. begin
  383. CPDB_LireEntierLong:=CPDB_CALL_ReadLongInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,piValue);
  384. end;
  385. Function CPDB_ReadLongInt(iHandle:UInt8;const sName:String;var piValue:Int32):Err;
  386. begin
  387. CPDB_ReadLongInt:=CPDB_CALL_ReadLongInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,piValue);
  388. end;
  389.  
  390. Function CPDB_LireChaine(iHandle:UInt8;const sNom:String;var phValue:MemHandle):Err;
  391. begin
  392. CPDB_LireChaine:=CPDB_CALL_ReadString(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sNom,phValue);
  393. end;
  394. Function CPDB_ReadString(iHandle:UInt8;const sNom:String;var phValue:MemHandle):Err;
  395. begin
  396. CPDB_ReadString:=CPDB_CALL_ReadString(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sNom,phValue);
  397. end;
  398.  
  399. Function CPDB_CompterEnregistrement(iHandle:UInt8;var piValue:UInt16):Err;
  400. begin
  401. CPDB_CompterEnregistrement:=CPDB_CALL_CountRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piValue);
  402. end;
  403. Function CPDB_CountRecord(iHandle:UInt8;var piValue:UInt16):Err;
  404. begin
  405. CPDB_CountRecord:=CPDB_CALL_CountRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piValue);
  406. end;
  407.  
  408. Function CPDB_RechercherNumerique(iHandle:UInt8;const sName:String;iValue:Int32;iMode:UInt8):Err;
  409. begin
  410. CPDB_RechercherNumerique:=CPDB_CALL_FindNumeric(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue,iMode);
  411. end;
  412. Function CPDB_FindNumeric(iHandle:UInt8;const sName:String;iValue:Int32;iMode:UInt8):Err;
  413. begin
  414. CPDB_FindNumeric:=CPDB_CALL_FindNumeric(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue,iMode);
  415. end;
  416.  
  417. Function CPDB_Trier(iHandle:UInt8;const sName:String;iDirection:UInt8):Err;
  418. begin
  419. CPDB_Trier:=CPDB_CALL_Sort(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iDirection);
  420. end;
  421. Function CPDB_Sort(iHandle:UInt8;const sName:String;iDirection:UInt8):Err;
  422. begin
  423. CPDB_Sort:=CPDB_CALL_Sort(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iDirection);
  424. end;
  425.  
  426. Function CPDB_ListerRubrique(iHandle:UInt8;var phList:MemHandle):Err;
  427. begin
  428. CPDB_ListerRubrique:=CPDB_CALL_ListField(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,phList);
  429. end;
  430. Function CPDB_ListField(iHandle:UInt8;var phList:MemHandle):Err;
  431. begin
  432. CPDB_ListField:=CPDB_CALL_ListField(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,phList);
  433. end;
  434.  
  435. Function CPDB_Rechercher(iHandle:UInt8;const sName:String;const sValue:String;iMode:UInt8):Err;
  436. begin
  437. CPDB_Rechercher:=CPDB_CALL_Find(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,sValue,iMode);
  438. end;
  439. Function CPDB_Find(iHandle:UInt8;const sName:String;const sValue:String;iMode:UInt8):Err;
  440. begin
  441. CPDB_Find:=CPDB_CALL_Find(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,sValue,iMode);
  442. end;
  443.  
  444. Function CPDB_Positionner(iHandle:UInt8;iPosition:UInt16):Err;
  445. begin
  446. CPDB_Positionner:=CPDB_CALL_SeekDirect(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,iPosition);
  447. end;
  448. Function CPDB_SeekDirect(iHandle:UInt8;iPosition:UInt16):Err;
  449. begin
  450. CPDB_SeekDirect:=CPDB_CALL_SeekDirect(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,iPosition);
  451. end;
  452.  
  453. Function CPDB_LirePosition(iHandle:UInt8;var piPosition:Int16):Err;
  454. begin
  455. CPDB_LirePosition:=CPDB_CALL_ReadPosition(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piPosition);
  456. end;
  457. Function CPDB_ReadPosition(iHandle:UInt8;var piPosition:Int16):Err;
  458. begin
  459. CPDB_ReadPosition:=CPDB_CALL_ReadPosition(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,piPosition);
  460. end;
  461.  
  462. Function CPDB_LireVersion(iHandle:UInt8;var phValue:MemHandle):Err;
  463. begin
  464. CPDB_LireVersion:=CPDB_CALL_ReadVersion(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,phValue);
  465. end;
  466. Function CPDB_ReadVersion(iHandle:UInt8;var phValue:MemHandle):Err;
  467. begin
  468. CPDB_ReadVersion:=CPDB_CALL_ReadVersion(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,phValue);
  469. end;
  470.  
  471. Function CPDB_DatabaseExiste(const sName:String):Err;
  472. begin
  473. CPDB_DatabaseExiste:=CPDB_CALL_DatabaseExist(CPDB_REFNUM,CPDB_CLIENTCONTEXT,sName);
  474. end;
  475. Function CPDB_DatabaseExist(const sName:String):Err;
  476. begin
  477. CPDB_DatabaseExist:=CPDB_CALL_DatabaseExist(CPDB_REFNUM,CPDB_CLIENTCONTEXT,sName);
  478. end;
  479.  
  480. Function CPDB_CreerDatabase(iCardNo:UInt16;const sNom:String;iCreator:UInt32;const sDescription:String):Err;
  481. begin
  482. CPDB_CreerDatabase:=CPDB_CALL_CreateDatabase(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iCardNo,sNom,iCreator,sDescription);
  483. end;
  484. Function CPDB_CreateDatabase(iCardNo:UInt16;const sNom:String;iCreator:UInt32;const sDescription:String):Err;
  485. begin
  486. CPDB_CreateDatabase:=CPDB_CALL_CreateDatabase(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iCardNo,sNom,iCreator,sDescription);
  487. end;
  488.  
  489. Function CPDB_AjouteEnregistrement(iHandle:UInt8):Err;
  490. begin
  491. CPDB_AjouteEnregistrement:=CPDB_CALL_AddRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  492. end;
  493. Function CPDB_AddRecord(iHandle:UInt8):Err;
  494. begin
  495. CPDB_AddRecord:=CPDB_CALL_AddRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  496. end;
  497.  
  498. Function CPDB_EcrireEntierCourt(iHandle:UInt8;const sName:String;iValue:Int8):Err;
  499. begin
  500. CPDB_EcrireEntierCourt:=CPDB_CALL_WriteShortInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue);
  501. end;
  502. Function CPDB_WriteShortInt(iHandle:UInt8;const sName:String;iValue:Int8):Err;
  503. begin
  504. CPDB_WriteShortInt:=CPDB_CALL_WriteShortInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue);
  505. end;
  506.  
  507. Function CPDB_EcrireEntier(iHandle:UInt8;const sName:String;iValue:Int16):Err;
  508. begin
  509. CPDB_EcrireEntier:=CPDB_CALL_WriteInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue);
  510. end;
  511. Function CPDB_WriteInt(iHandle:UInt8;const sName:String;iValue:Int16):Err;
  512. begin
  513. CPDB_WriteInt:=CPDB_CALL_WriteInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue);
  514. end;
  515.  
  516. Function CPDB_EcrireEntierLong(iHandle:UInt8;const sName:String;iValue:Int32):Err;
  517. begin
  518. CPDB_EcrireEntierLong:=CPDB_CALL_WriteLongInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue);
  519. end;
  520. Function CPDB_WriteLongInt(iHandle:UInt8;const sName:String;iValue:Int32):Err;
  521. begin
  522. CPDB_WriteLongInt:=CPDB_CALL_WriteLongInt(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,iValue);
  523. end;
  524.  
  525. Function CPDB_EcrireChaine(iHandle:UInt8;const sName:String;const sValue:String):Err;
  526. begin
  527. CPDB_EcrireChaine:=CPDB_CALL_WriteString(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,sValue);
  528. end;
  529. Function CPDB_WriteString(iHandle:UInt8;const sName:String;const sValue:String):Err;
  530. begin
  531. CPDB_WriteString:=CPDB_CALL_WriteString(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle,sName,sValue);
  532. end;
  533.  
  534. Function CPDB_MettreAJourEnregistrement(iHandle:UInt8):Err;
  535. begin
  536. CPDB_MettreAJourEnregistrement:=CPDB_CALL_UpdateRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  537. end;
  538. Function CPDB_UpdateRecord(iHandle:UInt8):Err;
  539. begin
  540. CPDB_UpdateRecord:=CPDB_CALL_UpdateRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  541. end;
  542.  
  543. Function CPDB_SupprimerEnregistrement(iHandle:UInt8):Err;
  544. begin
  545. CPDB_SupprimerEnregistrement:=CPDB_CALL_DeleteRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  546. end;
  547. Function CPDB_DeleteRecord(iHandle:UInt8):Err;
  548. begin
  549. CPDB_DeleteRecord:=CPDB_CALL_DeleteRecord(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  550. end;
  551.  
  552. Function CPDB_RAZ(iHandle:UInt8):Err;
  553. begin
  554. CPDB_RAZ:=CPDB_CALL_Clear(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  555. end;
  556. Function CPDB_Clear(iHandle:UInt8):Err;
  557. begin
  558. CPDB_Clear:=CPDB_CALL_Clear(CPDB_REFNUM,CPDB_CLIENTCONTEXT,iHandle);
  559. end;
  560.  
  561. {*
  562.  * FUNCTION: CPDBSTD_CloseLibrary
  563.  *
  564.  * DESCRIPTION:
  565.  *
  566.  * User-level call to closes the shared library. This handles removal
  567.  * of the library from system if there are no users remaining.
  568.  *
  569.  * PARAMETERS:
  570.  *
  571.  * refNum
  572.  * Library reference number obtained from CPDBSTD_OpenLibrary().
  573.  *
  574.  * clientContext
  575.  * client context (as returned by the open call)
  576.  *
  577.  * CALLED BY: Whoever wants to close the library
  578.  *
  579.  * RETURNS:
  580.  * errNone
  581.  * sysErrParamErr
  582.  *}
  583. Function CPDBSTD_CloseLibrary(refNum:UInt16;clientContext:UInt32):Err;
  584. label 99;
  585. var
  586. Error,rc:Err;
  587. begin
  588. if refNum=sysInvalidRefNum then begin
  589. CPDBSTD_CloseLibrary:=sysErrParamErr;
  590. //exit;
  591. goto 99;
  592. end;
  593. Error:=CPDBSTDClose(refNum,clientContext);
  594. if Error=errNone then
  595. rc:=sysLibRemove(refNum)
  596. else
  597. if Error=CPDBSTDErrStillOpen then
  598. Error:=errNone;
  599. CPDBSTD_CloseLibrary:=Error;
  600. 99:
  601. end;
  602.  
  603. {*
  604.  * FUNCTION: CPDBSTD_OpenLibrary
  605.  *
  606.  * DESCRIPTION:
  607.  *
  608.  * User-level call to open the library. This inline function
  609.  * handles the messy task of finding or loading the library
  610.  * and calling its open function; including handling cleanup
  611.  * if the library could not be opened.
  612.  *
  613.  * PARAMETERS:
  614.  *
  615.  * refNumP
  616.  * Pointer to UInt16 variable that will hold the new
  617.  * library reference number for use in later calls
  618.  *
  619.  * clientContextP
  620.  * pointer to variable for returning client context. The client context is
  621.  * used to maintain client-specific data for multiple client support. The
  622.  * value returned here will be used as a parameter for other library
  623.  * functions which require a client context.
  624.  *
  625.  * CALLED BY: System
  626.  *
  627.  * RETURNS:
  628.  * errNone
  629.  * memErrNotEnoughSpace
  630.  * sysErrLibNotFound
  631.  * sysErrNoFreeRAM
  632.  * sysErrNoFreeLibSlots
  633.  *
  634.  * SIDE EFFECTS:
  635.  * *clientContextP will be set to client context on success, or zero on
  636.  * error.
  637.  *}
  638. Function CPDBSTD_OpenLibrary(var refNumP:UInt16;var clientContextP:UInt32):Err;
  639. var
  640. Error,rc:Err;
  641. Loaded:Boolean;
  642. begin
  643. Loaded:=false;
  644. Error:=sysLibFind(CPDBSTDName,refNumP);
  645. if Error=sysErrLibNotFound then begin
  646. Error:=sysLibLoad(CPDBSTDTypeID,CPDBSTDCreatorID,refNumP);
  647. Loaded:=true;
  648. end;
  649. if Error=errNone then begin
  650. Error:=CPDBSTDOpen(refNumP,clientContextP);
  651. if Error<>errNone then begin
  652. if Loaded then
  653. rc:=sysLibRemove(refNumP);
  654. refNumP:=sysInvalidRefNum;
  655. end;
  656. end;
  657. CPDBSTD_OpenLibrary:=Error;
  658. end;
  659.  
  660. Procedure ErrDisplay(Msg:string);
  661. type
  662. PChar = StringPtr;
  663. function ErrAlertCustom(errCode: Err; errMsgP, preMsgP, postMsgP: PChar): UInt16; inline(SYSTRAP,$A365);
  664. var
  665. ErrAlert:UInt16;
  666. begin
  667. ErrAlert:=ErrAlertCustom(ErrOKAlert,@msg,nil,nil);
  668. end;
  669.  
  670. {*********************************************************************
  671.  * Macros for open & close lib
  672.  *********************************************************************}
  673.  
  674. Procedure CPDB_OPENLIB;
  675. var
  676. Error:Err;
  677. begin
  678. Error:=CPDBSTD_OpenLibrary(CPDB_REFNUM,CPDB_CLIENTCONTEXT);
  679. if Error<>errNone then
  680. ErrDisplay('Unable to open CPDB');
  681. end;
  682.  
  683. Procedure CPDB_CLOSELIB;
  684. var
  685. Error:Err;
  686. begin
  687. Error:=CPDBSTD_CloseLibrary(CPDB_REFNUM,CPDB_CLIENTCONTEXT);
  688. if Error<>errNone then
  689. ErrDisplay('Unable to close CPDB');
  690. end;