home *** CD-ROM | disk | FTP | other *** search
- This hint shows how to add a user hook into the "list_n_choose()" function
- from DB_LIST.C.
-
- PART I - How to insert the hook into the code of DB_LIST.C (DB_LIST.H)
- ----------------------------------------------------------------------
-
- First introduce a "procedureal" type to DB_LIST.H, and an associated variable
- of this new type :--
-
- typedef void (*listuserhook)(int fno, int kno, long rno, char thekey);
-
- extern listuserhook _dblisthook;
-
-
- Also add the variable declaration to DB_LIST.C (which it where the "extern"al
- refers to) :--
-
- listuserhook _dblisthook;
-
-
- The idea is that the "_dblisthook" is to be called if any of the extended
- keyboard keys are pressed, (the function keys, <Ctrl>+Key etcetera). The
- exceptions being those keys that have already got a purpose, (EG <Alt>+"Z"
- is already used for "Zoom").
-
- Add in code to the "default" part of the switch statement that processes the
- "action" inside the "list_n_choose()" function :--
-
- default:
- slen = strlen(search);
- if (!_xkey) {
- ...
- refilltab();
- }
- else { /*MOD*/
- if (_dblisthook != NULL) { /*MOD*/
- fval = labs((*rectab)[((pno+midlist-2)%listlen)+1].ref); /*MOD*/
- _dblisthook(fno,kno,fval,action); /*MOD*/
- refilltab(); /*MOD*/
- } /*MOD*/
- } /*MOD*/
- break;
-
- Finally we need to initialize the user hook to "NULL" as, by default, there
- is no function defined to be called!! In the unit initialization add :--
-
- _dblisthook = NULL;
-
-
- PART II - An example of how the hook might be used.
- -----------------------------------------------------
- Assume that you have a database, TEST, defined and in the fields for file 1
- there is a Display field called TAGFIELD with input picture "U". This field
- is NOT part of any key.
-
- Copy DBC.SKL to TEST.SKL and make the following modifications :--
-
- Near the end of the code, just before the main program block add in the
- following function :--
-
- void tagDuringList(int fno, int kno, long rno, uchar thekey)
- {
- ptr savbuf;
-
- if ((fno == 1) && (thekey == F9)) { /*use F9 to toggle TAG*/
- savbuf = db_malloc(TEST1.datasize); /*allocate a save buffer memory*/
- memmove(savbuf,&TEST1,TEST1.datasize); /*save existing record buffer*/
- getrec(datf[fno],rno,&TEST1);/*Get the record highlighted in the "List"*/
- if (TEST1.TAGFIELD[0] == '√') /*if its a tick blank it out*/
- TEST1.TAGFIELD[0] = ' ';
- else
- TEST1.TAGFIELD[0] = '√'; /*otherwise make it a tick*/
- putrec(datf[fno],rno,&TEST1); /*save change to disk*/
- memmove(&TEST1,savbuf,TEST1.datasize);/*restore the saved record buffer*/
- db_free(savbuf); /*free save buffer memory*/
- }
- }
-
-
- Initialize the user hook into DB_LIST so it will point somewhere meaningful,
- that is initialize the procedureal pointer "_dblisthook" to the adddress of
- this function we've just implemented, "tagDuringList()".
-
- Begin
- ...
- _keyexpr = keyexpr;
- _getarec = getarec;
- _horizrec = horizrec;
- _dblisthook = tagDuringList; /*MOD*/
- ...
-
-
- The result of all this is that when we use the "Find" option for file 1 in
- the "TEST.EXE" application we will be able to toggle the "TAGFIELD" field
- between a tick, (√), and a space by pressing the <F9> function key.