home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / DBASE / DBX112.ZIP / MYFUNC.PRG < prev    next >
Text File  |  1992-04-07  |  15KB  |  448 lines

  1. * Program...: MYFUNC.PRG
  2. * Author....: Your Name Here
  3. * Date......:
  4. * Revised...:
  5. * Notes.....: This routine is called by pressing Sh-F1 when browsing a
  6. *             database.  You can create any routine you like by expanding
  7. *             the code below and linking the routine into dbMAX.  Sample
  8. *             code is included at the end of this file (commented-out).
  9. *
  10. *             Compile with -n -l switches
  11. *
  12. *****************************************************************************
  13. *
  14. #include "inkey.ch"
  15. *#include "dbfndx.ch"
  16. *
  17. function MyFunc( nKey,oBrowse,lEditMode,lNoAppend,lNoDelete,aField,;
  18.                  cEditFunc)
  19. *
  20. * nKey      = the ASCII value of the last key pressed, passed by reference
  21. *             (will always be -10/K_SH_F1)
  22. * oBrowse   = the current browse object, passed by reference
  23. * lEditMode = .T. if editing allowed
  24. * lNoAppend = .T. if no appending allowed (always .F.)
  25. * lNoDelete = .T. if no deleting allowed (always .F.)
  26. * aField    = DBSTRUCT() of all fields in database, passed by reference
  27. * cEditFunc = name of a user-defined edit routine (always '')
  28. *
  29. * Although some of the variables above have been passed by reference, any
  30. * changes to them will be ignored (see below for more info).
  31. *
  32. * NOTE:  PRESSING SH-F1 WHILE IN THE MENU SYSTEM WILL CALL MYFUNC(), BUT
  33. * ALL PARAMETERS WILL BE NIL!!  MOST ALL PARAMETERS CAN BE OBTAINED BY
  34. * CHECKING THE VARIABLES LISTED BELOW.
  35. *
  36. PopError('Function unavailable!')
  37. *
  38. return (nil)
  39. *
  40. *****************************************************************************
  41. *
  42. * The following variables are used by dbMAX and CAN be changed:
  43. *                                               ▀▀▀
  44. * vcPath      = current drive and path used by dbMAX (initially set to your
  45. *               current DOS path but changes when any pop-up directories are
  46. *               used (Alt-B, Alt-N, etc.))
  47. * vnInUse     = total number of work areas in use
  48. * vnCurrArea  = current work area number
  49. * vaDBFNTX    = array of .DBFs/.NTXs/open modes
  50. * vaBrowStak  = browse object stack
  51. * vlRepaint   = set to .T. to completely repaint desktop/browse(s)
  52. *
  53. * vcDosColr   = current DOS screen color
  54. * vcDeskTop   = desktop color
  55. * vcBrowse    = browse color
  56. * vcShadow    = box shadow color
  57. * vcMenuBar   = menu bar color
  58. * vcPullDown  = pull-down menu color
  59. * vcPullBox   = pull-down box border color
  60. * vcHotKey    = accelerator key color
  61. * vcError     = error message color
  62. *
  63. * vlMultiUser = .T. if running in multi-user mode
  64. * vcRamDrv    = temporary files drive
  65. * vcEditor    = default memo editor ("" = use MEMOEDIT())
  66. * vnMemoWidth = default memo line length (0 = screen width)
  67. * vcPrnSetup  = printer setup string
  68. * vnPageLen   = max lines per page
  69. * vnLeftMar   = left margin
  70. * vnTopMar    = top margin
  71. * vnMaxRow    = max rows on screen
  72. * vnInitRow   = max initial rows on screen (DOS)
  73. * vnMaxCol    = max columns on screen
  74. * vnInitCol   = max initial columns on screen (DOS)
  75. * vlDelStru   = .T. delete .STR files when done
  76. * vlAllowEdit = .T. if editing allowed
  77. * vlBadEMS    = .T. if bad EMS switch set (bypasses Overlay())
  78. *
  79. *
  80. * The most important variables are the vaDBFNTX and vaBrowStak arrays.  The
  81. * vaDBFNTX array contains a list of all open databases.  All elements in a
  82. * "row" will be NIL if a database was opened and then closed.  The number
  83. * of the array element that is currently active is stored in vnCurrArea,
  84. * which is also SELECT() (usually).  The structure for one element is as
  85. * follows:
  86. *
  87. * vaDBFNTX[1] = {"<drive:\path\>","dbase.dbf",{"index <drive:\path\>",;
  88. *               "index.ntx"},"E/S"}
  89. *
  90. *   vaDBFNTX[1,1] = the full drive and path with trailing backslash for the
  91. *                   database; i.e., "C:\DATA\"
  92. *   vaDBFNTX[1,2] = the full name and extension of the database; i.e.,
  93. *                   "MYDATA.DBF"
  94. *   vaDBFNTX[1,3] = an array of open indexes for the database; if no indexes
  95. *                   are open, this will be NIL
  96. *
  97. *     vaDBFNTX[1,3,1] = the full drive and path with trailing backslash for
  98. *                       the index; i.e., "C:\DATA\"
  99. *     vaDBFNTX[1,3,2] = the full name and extension of the index; i.e.,
  100. *                       "MYDATA.NTX"
  101. *
  102. *   vaDBFNTX[1,4] = "E" if file is opened exclusively, "S" if shared
  103. *
  104. * The vaBrowStak contains all the browse objects currently in use.  The
  105. * number of the array element that is currently active is stored in
  106. * vnCurrArea, which is normally the same as SELECT().  The structure for one
  107. * element is as follows:
  108. *
  109. * vaBrowStak[1] = {<oBrowse>,{<structure>}}
  110. *
  111. *   vaBrowStak[1,1] = the browse object; oBrowse:cargo contains append mode
  112. *                     flag; oColumn:cargo contains actual field name/
  113. *                     expression for the column
  114. *   vaBrowStak[1,2] = the structure of the database, the same as that
  115. *                     created by the DBSTRUCT() function
  116. *
  117. * Usage example:
  118. *
  119. *   * refresh the current browse window
  120. *   vaBrowStak[vnCurrArea,1]:refreshAll()
  121. *
  122. * ---------------------------------------------------------------------------
  123. * While dbMAX in its default configuration does not support the use of the
  124. * DBFNDX driver at this time, it can be added by the programmer.  dbMAX will
  125. * automatically begin using the .NDX extension for index files if the DBFNDX
  126. * driver is linked in and used.
  127. * ---------------------------------------------------------------------------
  128. *
  129. *
  130. * Some internal dbMAX functions that may be called by your routines are:
  131. *
  132. * ColStru() - returns the structure of a field/expression
  133. *
  134. *     Usage:   aArray := ColStru( cFieldName )
  135. *
  136. *     Where:   cFieldName = the name of a field or memory variable
  137. *
  138. *     Returns: {cFieldName,cType,nLength,nDecimals} array for a field or
  139. *              expression.  If cFieldName contains an expression, cType
  140. *              will be "E".
  141. *
  142. *     Example:
  143. *
  144. *       * returns the structure array for the field where a hot-key was
  145. *       * pressed
  146. *       *
  147. *       aArray := ColStru( (voBrowse:getColumn(voBrowse:colPos)):cargo )
  148. *
  149. *
  150. * PullDown() - sets up and displays menu system
  151. *
  152. *     Usage:   PullDown( nRow,nCol,aMenu,aHotKeys,aValid,aMessage,@nChoice )
  153. *
  154. *     Where:   nRow     = top row of the pop-up menu box.  If nRow=0, the
  155. *                         menu appears horizontally on line 0!
  156. *              nCol     = left column of the pop-up menu box
  157. *              aMenu    = array of menu choices
  158. *              aHotKeys = array of hot key letters for the menu choices,
  159. *                         "" for choices with no hot key (horizontal menus
  160. *                         will not use hot keys)
  161. *              aValid   = parallel logical array for valid menu choices
  162. *              aMessage = help bar messages to display when selecting
  163. *                         (horizontal menus will not use messages)
  164. *              nChoice  = variable to take menu selection, passed by ref.
  165. *
  166. *     Returns: NIL, but nChoice contains the number of the menu item
  167. *              selected, 0 if nothing was selected.
  168. *
  169. *     Example:
  170. *
  171. *       local nChoice := 0
  172. *       PullDown(1,1,{'  New...      Alt-N ',;
  173. *                     '  Open...     Alt-O ',;
  174. *                     ' ────────────────── ',;
  175. *                     '  Quit        Alt-Q '},{'N','O','','Q'},;
  176. *                     {.T.,.T.,.F.,.T.},{'Message 1','Message 2','',''},;
  177. *                     @nChoice)
  178. *
  179. *
  180. * HelpBar() - places a message on the help bar
  181. *
  182. *     Usage:   HelpBar( [cMessage] )
  183. *
  184. *     Where:   cMessage = any character string or NIL
  185. *
  186. *     Returns: NIL
  187. *
  188. *     Example:
  189. *
  190. *       HelpBar()                         // clears off help bar
  191. *       HelpBar('Press <Esc> to quit.')
  192. *
  193. *
  194. * PopBox() - pops up a single- or double-lined filled shadowed box
  195. *
  196. *     Usage:   PopBox( nTRow,nTCol,nBRow,nBCol,nBorder [,cTitle] )
  197. *
  198. *     Where:   nTRow   = top row of box
  199. *              nTCol   = top left col of box
  200. *              nBRow   = bottom row of box
  201. *              nBCol   = bottom left col of box
  202. *              nBorder = 1=single line, 2=double line
  203. *              cTitle  = optional title to be displayed (@ nTRow,nTCol+2)
  204. *
  205. *     Returns: NIL
  206. *
  207. *     Example:
  208. *
  209. *       PopBox(4,9,10,70,2,'Database name')
  210. *
  211. *
  212. * PopError()  - pops up an error message
  213. *
  214. *     Usage:   PopError( cMessage )
  215. *              nChoice := PopError( cMessage [,aPrompts] )
  216. *
  217. *     Where:   cMessage = any character string for the error message
  218. *              aPrompts = an optional array of selection options, defaults
  219. *                         to " Ok " if nothing passed
  220. *
  221. *     Returns: number of choice selected
  222. *
  223. *     Example:
  224. *
  225. *       PopError('Not enough file handles ('+ltrim(str(MaxHand()))+')!')
  226. *       nChoice := PopError('File exists!',{' Overwrite ',' Cancel '})
  227. *
  228. *
  229. * MaxHand()   - gets maximum number of file handles remaining
  230. *
  231. *     Usage:   MaxHand()
  232. *
  233. *     Returns: number of file handles remaining
  234. *
  235. *     Example:
  236. *
  237. *       @ 1,1 say 'You have '+ltrim(str(MaxHand()))+' handles remaining!'
  238. *
  239. *
  240. * fil_lock() - tries to lock a file
  241. *
  242. *     Usage:   fil_lock( nWait )
  243. *
  244. *     Where:   nWait = number of seconds to wait for the lock, 0=forever
  245. *
  246. *     Returns: .T. if lock was successful, .F. otherwise
  247. *
  248. *     Example:
  249. *
  250. *       if fil_lock(2)
  251. *         replace all field with 'stuff'
  252. *         commit
  253. *         unlock
  254. *       else
  255. *         PopError('File could not be locked!')
  256. *       endif
  257. *
  258. *
  259. * rec_lock() - tries to lock a record
  260. *
  261. *     Usage:   rec_lock( nWait )
  262. *
  263. *     Where:   nWait = number of seconds to wait for the lock, 0=forever
  264. *
  265. *     Returns: .T. if lock was successful, .F. otherwise
  266. *
  267. *     Example:
  268. *
  269. *       if rec_lock(2)
  270. *         delete
  271. *         commit
  272. *         unlock
  273. *       else
  274. *         PopError('Record could not be locked!')
  275. *       endif
  276. *
  277. *
  278. * net_use() - tries to USE a database in shared or exclusive mode
  279. *
  280. *     Usage:   net_use( cFile,lExclus,nWait )
  281. *
  282. *     Where:   cFile   = name of database to open
  283. *              lExclus = .T. to open file exclusively
  284. *              nWait = number of seconds to wait for the lock, 0=forever
  285. *
  286. *     Returns: .T. if open was successful, .F. otherwise
  287. *
  288. *     Example: none!  Don't use this function unless you are sure you know
  289. *              what's going on inside dbMAX.  If you do not update
  290. *              vnCurrArea and vnDBFNTX[] when this command is used, you may
  291. *              cause the program to crash or operate incorrectly.
  292. *
  293. *
  294. * app_blank() - tries to append a blank record to a shared database
  295. *
  296. *     Usage:   app_blank( nWait )
  297. *
  298. *     Where:   nWait = number of seconds to wait for the append, 0=forever
  299. *
  300. *     Returns: .T. if append was successful, .F. otherwise
  301. *
  302. *     Example:
  303. *
  304. *       if app_blank(2)
  305. *         replace field with 'stuff'
  306. *         commit
  307. *         unlock
  308. *       else
  309. *         PopError('LASTREC()+1 is locked.  Something is screwed up!')
  310. *       endif
  311. *
  312. *****************************************************************************
  313. *****************************************************************************
  314. *
  315. * Sample MYFUNC()
  316. *
  317. * *
  318. * function MyFunc()
  319. * *
  320. * local vnChoice := 1
  321. * local vcColrSave := setcolor(vcMenuBar)
  322. * local vcScreen
  323. * *
  324. * save screen to vcScreen
  325. * @ 0,0                                 && clear off default menu bar
  326. * HelpBar('Shift-F1 Main Menu.')
  327. * setcolor(vcColrSave)
  328. * *
  329. * do while vnChoice<>0
  330. *   PullDown(0,2,{'  Option 1  ',;
  331. *                 '  Option 2  ',;
  332. *                 '  Option 3  '},;
  333. *                 {'1','2','3'},{.T.,.T.,.T.},nil,@vnChoice)
  334. *   *
  335. *   do case
  336. *     case vnChoice=1
  337. *       HelpBar('Option 1 tasks menu.')
  338. *       if Sample()
  339. *         vnChoice := 0
  340. *       endif
  341. *       *
  342. *     case vnChoice=2
  343. *       HelpBar('Option 2 tasks menu.')
  344. *       PopError('Option 2 unavailable!')
  345. *       *
  346. *     case vnChoice=3
  347. *       HelpBar('Option 3 tasks menu.')
  348. *       PopError('Option 3 unavailable!')
  349. *       *
  350. *     otherwise
  351. *       vnChoice := 0
  352. *       *
  353. *   endcase
  354. *   *
  355. *   HelpBar()
  356. *   *
  357. * enddo
  358. * restore screen from vcScreen
  359. * return (nil)
  360. * *
  361. * *****************************************************************************
  362. * *
  363. * static function Sample()
  364. * *
  365. * local vnChoice := 1
  366. * local vlRetVal := .F.         && .T.=exited normally, .F.=used Esc to exit
  367. * local vcScreen
  368. * *
  369. * local vaMenu := {'  Check this ',;
  370. *                  ' ─────────── ',;
  371. *                  '  Allow edit ',;
  372. *                  '  In use > 0 ',;
  373. *                  '  Browse     '}
  374. * *
  375. * local vaHotKeys := {'C','','A','I','B'}
  376. * local vaValid := {.T.,.F.,vlAllowEdit,(vnInUse>0),(vnInUse>0)}
  377. * local vaMessage := {'Check/uncheck this item by pressing <Enter>.','',;
  378. *                     'Selectable if editing allowed.',;
  379. *                     'Selectable if at least one .DBF opened.',;
  380. *                     'Changes the color of the hilighted column.'}
  381. * *
  382. * save screen to vcScreen
  383. * *
  384. * do while vnChoice<>0
  385. *   *
  386. *   * set left/right arrow keys for wrapping menu to other options
  387. *   *
  388. *   setkey(K_RIGHT, {|| __Keyboard(chr(K_ESC)+chr(K_RIGHT)+chr(K_ENTER)) })
  389. *   setkey(K_LEFT, {|| __Keyboard(chr(K_ESC)+chr(K_LEFT)+chr(K_ENTER)) })
  390. *   *
  391. *   PullDown(1,1,vaMenu,vaHotKeys,vaValid,vaMessage,@vnChoice)
  392. *   *
  393. *   * turn off keys
  394. *   *
  395. *   setkey(K_RIGHT,nil)
  396. *   setkey(K_LEFT,nil)
  397. *   *
  398. *   do case
  399. *     case vnChoice=1
  400. *       vaMenu[1] := iif(substr(vaMenu[1],1,1)=' ','√',' ')+;
  401. *        substr(vaMenu[1],2)
  402. *       *
  403. *     case vnChoice=3
  404. *       restore screen from vcScreen
  405. *       *
  406. *       *if YourOption()        && if .T. (task complete), quits back to
  407. *       *  vnChoice := 0        && dbMAX menu or browse
  408. *       *  vlRetVal := .T.
  409. *       *endif
  410. *       *
  411. *     case vnChoice=4
  412. *       restore screen from vcScreen     && don't RESTORE if you want the
  413. *       *                                   pull-down to stay on the screen
  414. *       *
  415. *       *MoreStuff()            && quits to dbMAX menu or browse whether task
  416. *       vnChoice := 0           && was completed or not
  417. *       vlRetVal := .T.
  418. *       *
  419. *     case vnChoice=5
  420. *       ChangeColor()
  421. *       vnChoice := 0
  422. *       vlRetVal := .T.
  423. *       *
  424. *   endcase
  425. * enddo
  426. * restore screen from vcScreen
  427. * *
  428. * return (vlRetVal)
  429. * *
  430. * *****************************************************************************
  431. * *
  432. * static function ChangeColor()
  433. * *
  434. * * Changes color of the currently highlighted column.  Can only be called if
  435. * * a file is being browsed, so error checking is not required.  :colorSpec
  436. * * is initially set to vcBrowse color.
  437. * *
  438. * local voBrowse := vaBrowStak[vnCurrArea,1]              && get curr browse
  439. * local voColumn := voBrowse:getColumn(voBrowse:colPos)   && get column
  440. * *
  441. * voBrowse:colorSpec := voBrowse:colorSpec+',+BG/B,+W/G'
  442. * voColumn:colorBlock := {|| {6,7} }
  443. * *
  444. * voBrowse:setColumn(voBrowse:colPos,voColumn)            && reset column
  445. * *
  446. * vaBrowStak[vnCurrArea,1] := voBrowse                    && save browse
  447. * return (nil)
  448.