home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource1
/
chint
/
useful13.hnt
< prev
next >
Wrap
Text File
|
1992-12-07
|
3KB
|
106 lines
This hint shows how to use the existing "Add_Record" routine to add records
on the fly to another file in the current system.
### WARNING ###
This functionality should not be invoked on a linked file as the DataBoss
internal linking would, in all probability, be compromised
### WARNING ###
Step (1) Copy the standard skeleton read for customisation...
COPY DBC.SKL DBCFLY.SKL
Step (2) Add a new global boolean variable...
bool specListAndAdd;
Step (3) Add two new prototypes...
long specialadd(int fno);
strptr speclistadd(keystr sout, int fno, int kno, keystr ks);
Step (4) Modify the first line of the "list()" function to...
if (!(listAndAdd || specListAndAdd)) listing = True; /*MOD*/
Step (5) Add a new line to the "list()" function...
...
if (trecno == 0 && listAndAdd) trecno = add2CodeFile(fno);
if ((trecno == 0) && specListAndAdd) trecno = specialadd(fno); /*NEW*/
if (trecno > 0) {
...
Step (6) After the end of the existing "listadd()" function add in the
following new function...
strptr speclistadd(keystr sout, int fno, int kno, keystr ks)
{
specListAndAdd = True;
list(sout,fno,kno,ks);
specListAndAdd = False;
return(sout);
}
Step (7) After the end of the "add_record()" function add in another new
function "specialadd()"...
long specialadd(int fno)
{
bool saveDisp;
int saveFilno, saveScrno, saveFldNum;
editGlobalVars saveEDT;
saveFilno = filno;
saveScrno = scrno;
saveFldNum = fldnum;
memmove(&saveEDT,&edt,sizeof(editGlobalVars));
filno = fno;
scrno = winforfile[filno];
saveDisp = uw.wa[scrno]->disp;
selectwin(uw.wa[scrno]);
if (!saveDisp) hidewin(T_ON,uw.wa[scrno]);
add_record(_Add);
if (!saveDisp) hidewin(T_OFF,uw.wa[scrno]);
exitcode = Nul;
memmove(&edt,&saveEDT,sizeof(editGlobalVars));
fldnum = saveFldNum;
scrno = saveScrno;
for (filno=1;filno<=16;filno++){ if (uw.wa[filno] != NULL) selectwin(uw.wa[filno]);}
filno = saveFilno;
return(recno[fno]);
}
Step (8) This modification to the custom skeleton is to add a line of code
to "initialize()" to ensure the new variable is initialized...
specListAndAdd = False;
filinuse[X] = False;
Replace "X" with the number of the file in for the "specialadd"
will work.
Step (9) When defining a database you can combine a "Validation Expression"
found(<fno>,1,{})
with a call to the new "speclistadd()" in the "Error Expression"
speclistadd(_tts,<fno>,1,{})
Where <fno> is the number of another non-linked file in the
current definition that has fields that are editable on some
other window.