home *** CD-ROM | disk | FTP | other *** search
- /*
- DBFLIB.DO
- This is a collection of methods for handling DBASE files
- Includes:
- Dbffile::displayStructure(self)
- Dbffile::copyStructure(self)
- Dbffile::list(self)
- Dbffile::edit(self)
- */
- #include "keydef.do"
- #include "colors.do"
-
- /*
- Dbffile::displayStructure(self)
- this methods prints a description of the structure of a DBASE
- file similar to that in the DBASE DISPLAY STRUCTURE command
- */
- method Dbffile::displayStructure(self)
- {
- ? "Structure for\t\t",name(self);
- ? "Last udpate:\t\t",date(self);
- ? "Number of records:\t",numRecords(self);
- fields = structure(self);
- ? "FIELD\t\t\t\TYPE\tLEN\tDEC";
- for(i=1;i<numFields(self);i=i+1) {
- f = at(fields,i);
- ? format(at(f,1),"%-24s"),at(f,2),"\t",
- at(f,3),"\t",at(f,4);
- }
- }
-
- /*
- Dbffile::copyStructure(self,newname)
- this method copys the structure of self to a new database
- with name of "newname"
- only the structure of self is copied; no records are copied
- */
- method Dbffile::copyStructure(self,newname)
- {
- l = structure(self);
- createDbf(newname,l);
- }
-
- /*
- Dbffile::list(self)
- this method lists the records in a Dbffile to the screen
- */
- method Dbffile::list(self)
- {
- top(self);
- fields = structure(self);
- newline = set("newline");
- set("newline","");
- while(!eof(self)) {
- for(i=1;i<numFields(self);i=i+1) {
- f = at(fields,i);
- name = at(f,1);
- ? eval(asId(name))," ";
- }
- ? "\n";
- skip(self,1L);
- }
- set("newline",newline);
- }
-
- /*
- The following methods implement a DBASE field editor using the
- dObject Window SAY, GET, and READ methods.
- first, define a new class called MYFIELD that inherits the behavior of
- Field, but adds a prompt that is displayed at the bottom of the form
- */
- inherit(Field,Myfield,["prompt"]);
-
- /*
- define a method to get the prompt field from a Myfield variable
- */
- method Myfield::prompt(self)
- {
- return(slot(self,"prompt"));
- }
-
- /*
- this method will execute whenever the DOWN key is pressed
- from within a form
- */
- method Window::myNextField(self)
- {
- n = num(currentField(self));
- if(n < len(fields)) {
- f = at(fields,n+1);
- say(promptWindow,0,0,prompt(f),80,112);
- gotoField(self,nextField(self));
- }
-
- }
-
- /*
- this method will execute whenever the UP key is pressed
- from within a form
- */
- method Window::myPrevField(self)
- {
- n = num(currentField(self));
- if(n > 1) {
- f = at(fields,n-1);
- say(promptWindow,0,0,prompt(f),80,112);
- gotoField(self,prevField(self));
- }
- }
-
- /*
- this method implements a callable text editor for the contents of
- a field
- */
- method Window::myEdit(self)
- {
- f = currentField(self);
- s = eval(asId(name(f)));
- if(class(s) == "String") {
- w = new(Window,1,31,3,name(f),5,5,10,40);
- display(s);
- remove(w);
- gotoField(self,f);
- }
- }
-
- /*
- edit a Dbffile using a full screen editor
- */
- method Dbffile::edit(self)
- {
- /*
- make a window to run the editor in
- */
- w = new(Window,1,FWHITE+LIGHTBLUE,FWHITE+LIGHTBLUE,
- name(self),0,0,24,80);
-
- /*
- create the DBASE form based on field definitions within self
- */
- clearGets(w);
- sayExp(w,0,1,#name(self),len(name(self)),FWHITE+LIGHTBLUE);
- sayExp(w,0,20,#"Record=",7,FWHITE+LIGHTBLUE);
- sayExp(w,0,30,#recno(self),7,FWHITE+LIGHTBLUE);
-
- l = structure(self);
- fields = [];
-
- /*
- for each field in the DBF file, create:
- a SAY field with the name of the DBF field
- a GET field right next to it to read its value
- */
- for(i=1;i<=numFields(self);i=i+1) {
- field_def = at(l,i);
- fname = at(field_def,1); % name is first element in field def
- len = at(field_def,3);
- if(len > 40) len = 40;
- say(w,i,1,fname,10,31);
- fields = append(fields,new(Myfield,w,i,15,fname,len,112,
- "Enter the "+asUpper(trim(fname))+ " field"));
-
- }
-
- /*
- execute the form
- */
- top(self);
- promptWindow = new(Window,80,112,0,"",24,0,1,80);
-
- onKey(w,DOWN,#myNextField(w));
- onKey(w,UP,#myPrevField(w));
- onKey(w,F8,#myEdit(w));
-
- say(promptWindow,0,0,prompt(at(fields,1)),80,112);
-
- read(w);
- remove(w);
- remove(promptWindow);
- }
-