home *** CD-ROM | disk | FTP | other *** search
- /* Webwizard.cc Class Library for Visual dBASE 7 Web Wizards
- Author: A.A.Katz <KSoft, inc.)
- (c) 1997 All Rights Reserverd, Borland International
- Version 1.0 10-10-1997
-
- Includes Class Sourcefields
- Class TextFields
- */
-
-
- #DEFINE QueryName 1
- #DEFINE FieldList 2
-
- /////////////// Class SourceFields /////////////////////////////////////////
- /////////////// Attempts to open table/datamodule and read in queries
- /////////////// and fields ///////////////////////////////////////////////
- ////////////////Param: cSourcePath = fully qualified path to table or
- //////////////// dataModule
-
- Class SourceFields(cSourcePath) of Array
-
- local n
-
- /*Important note: Must re-instantiate each time you call this method
- or array will not be empty.
- */
-
-
- this.cDataPath = ' '
- this.dMod = ''
- this.cDataType = 'DataModule'
-
-
- ////// Method: GetFields ////////////////////////////////////////////
- ////// Purpose: Opens DataModule or Table and reads in queries/Fields
- ////// Params: oParent reference to parent form
- ////// cDataPath: Disk file path to Data Module or Table
-
- function GetFields(cSourcePath,bIsFromReport)
-
- local n
- private aRetValue
- aRetValue = new array() // instantiate for return values
-
- this.cDataPath = trim(cSourcePath)
- this.cPath = ''
- if at('\',this.cDataPath) > 0
- this.cPath = substr(this.cDataPath,1,rat('\',this.cDataPath))
- endif
- this.nHnd = -1
-
- // if it's a data module rather than a table
- if upper(right(this.cDataPath,4)) = '.DMD' or bIsFromReport
-
- this.cDataType = 'DataModule'
-
-
- // attempt to open .dmd file readonly with low-level file IO
-
- this.nHnd = fOpen(this.cDataPath,'R')
-
- if this.nHnd < 0 // if file fails to open
- msgbox('Unable to open file: '+this.oParent.TableField.value)
- fClose(this.nHnd)
- return aRetValue // go back/failed
- endif
-
-
- // Parse out Class name for data module and attempt to open it
-
- do
-
- cStr = trim(fGets(this.nHnd))
-
- if at('CLASS ',upper(cStr)) > 0 and at('OF',upper(cStr)) > 0
-
- // get class name
- cStr = ltrim(substr(cStr,at('CLASS',upper(cStr))+5))
- cName = trim(substr(cStr,1,at(' ',cStr)-1))
- // build macro string
-
- try
-
- // attemp to instantiate data module
-
- set proc to (this.cDataPath) addi
-
- catch ( Exception e )
-
- msgbox('Unable to load datamodule: '+this.cDataPath+;
- chr(13)+e.message)
- return aRetValue
-
- endtry
-
-
- // try to change directory before opening Data Module
-
-
- cCurrPath = set('DIRECTORY')
-
- if len(trim(this.cPath)) > 0
-
- try
- cPath = this.cPath
- cd (cPath)
-
- catch (Exception e)
-
- msgbox('Unable to access directory: '+cPath+;
- chr(13)+e.message)
-
- cPath = cCurrPath // restore directory
- cd (cPath)
- return aRetValue // return empty array
-
- endtry
-
- endif
-
- // Instantiate data module
-
- try
-
- this.dMod = new &cName.()
-
- catch ( Exception e )
-
- msgbox('Unable to create new instance of class: '+cName+;
- chr(13) + e.message+;
- chr(13) + 'File: '+e.filename+;
- chr(13) + 'Line: '+str(e.lineno,5))
-
- fClose(this.nHnd)
- cPath = cCurrPath
- cd (cPath)
- return aRetValue
-
- endtry
-
- // return to default path
- cPath = cCurrPath
- cd (cPath)
-
- exit
-
- endif
-
-
- Until fEof(this.nHnd)
-
-
-
- // parse out the query classes in this data module
-
- do
-
-
- cStr = ltrim(trim(fGets(this.nHnd))) // read in one line
-
- if at('NEW QUERY()',upper(cStr)) > 0 // see if it's a query declaration
-
- // parse out query declaration
- cName = substr(cStr,1,at(' ',cStr)-1)
-
- if at('THIS.',upper(cName)) > 0 // if "this." in line, remove it
- cName = substr(cName,at('THIS.',upper(cName))+5)
- endif
-
- if len(trim(cName)) > 0 // add query name to array
-
- this.resize(alen(this,1)+1,2)
- n= alen(this,1)
- this[n,QueryName] = cName
-
- endif
-
- endif
-
- Until feof(this.nHnd)
-
- fClose(this.nHnd)
-
- // traverse rowsets and store fieldnames in this array
- for n = 1 to alen(this,1)
- class::getFieldNames(n)
- next
-
- // set return value = a single-dim array with "aliases"
- aRetValue = class::GetAvailableFieldsArray()
-
- else // if it's a table
-
- this.cDataType = 'Table'
-
- cName = substr(this.cDataPath,1, rat('.',this.cDataPath)-1)
-
- if at('\',cName) > 0
- cName = substr(cName,rat('\',this.cDataPath)+1)
- // attempt table open
- endif
-
- // Change directory before opening query
-
- cCurrPath = set('DIRECTORY')
-
-
- if len(trim(this.cPath)) > 0
- Try
-
- cPath = this.cPath
- cd (cPath)
-
- Catch (Exception e)
- msgbox('Unable to access directory: '+cPath+;
- chr(13)+e.message)
- return aRetValue // return empty array
-
- EndTry
-
- endif
-
-
-
- // Try to open table in query
- try
-
- this.q = new Query()
- this.q.SQL = 'select * from "'+this.cDataPath+'"'
- this.q.active = true
-
- catch ( Exception e )
- // check exception and give detailed error message
-
- msgbox('Unable to open table: '+this.cDataPath+;
- chr(13)+e.message)
-
-
- // go back / failed
- if this.nHnd > 0
- fClose(this.nHnd)
- endif
-
- cPath = cCurrPath
- cd (cPath)
-
- return aRetValue
- endtry
-
- cPath = cCurrPath
- cd (cPath)
- // remove file extension
-
- // add element to array for this table and store table name
-
-
- this.resize(alen(this,1)+1,2)
- n = alen(this,1)
- this[n,QueryName] = cName
-
- Class::GetFieldNames(n)
- aRetValue = class::GetAvailableFieldsArray()
-
-
- endif
-
- return aRetValue // return Available Fields array
-
-
- /////Method: GetFieldNames ////////////////////////////////////////
- /////Purpose: Parses the fields[] array of a query object for
- ///// field names
- ///// Stores fieldnames in the FieldList [n,2] element
- ///// of the main array class
- /////Param: n - the current array element of the main array
-
- function GetFieldNames(n)
- local n2
- private cQueryName,cLen,nLen
-
- // Get length of fields array in rowset
-
- if this.cDataType = 'DataModule'
- cQueryName = "this.dMod."+this[n,QueryName]
- else
- cQueryName = "this.q"
- endif
-
- cLen = cQueryName+'.rowset.fields.size'
- nLen = &cLen
-
- // create fieldname array as element of main array
-
- this[n,FieldList] = New Array()
-
-
- // populate array with fieldnames
-
- for n2= 1 to nLen
- // set up macro for fields[n].fieldname
- cFieldMacro = cQueryName+".rowset.fields["+;
- ltrim(trim(str(n2,4)))+"].fieldname"
- cFieldName = &cFieldMacro. // expand macro
-
- this[n,Fieldlist].Add(cFieldName)// add element/fieldname to array
-
- next
-
-
- /////Method: GetAvailableFieldsArray()
- /////Purpose: Traverses This.array and makes a new array in
- ///// single dimension
- function GetAvailableFieldsArray
-
- local n
- a = new array() // create array to pass back to form
- // loop through main array
- for n = 1 to alen(this,1)
-
- cQuery = this[n,QueryName] // for each query in main array
- // enumerate the fields array
-
- for n2 = 1 to alen(this[n,FieldList],1)
- a.add(cQuery+'->'+this[n,FieldList][n2])
- next
- next
-
- return a // return the resultant array
-
-
-
- endclass /// end of class
-
-
-
- /*
- Class TextFields - gets streamsource text items from report file
- Params: - cRepPath Path to Report file
-
- */
-
- Class TextFields of Array
-
-
- ////////////////Method GetTextFields//////////////////////////////////////
- ////////////////Purpose: Gets text fields from report file ///////////////
- ////////////////Params: None /////////////////////////////////////////////
-
- function GetTextFields(cRepPath)
- local nHnd
-
-
-
- nHnd = fOpen(cRepPath)
- if nHnd < 0 // if you cannot open report file
- msgbox('Cannot open '+cRepPath)
- return this // return empty array
- endif
-
- do
-
- // read in the next line
- cStr = upper(fGets(nHnd))
-
- // if it's a fields text object
- if at('{||', cStr) > 0 .and. at('FIELDS',cStr) > 0
- // add fieldname to this array
-
- this.add(cStr.SubString(at('FIELDS["',cStr)+7,;
- at('"]',cStr)-1))
-
- endif
-
-
- until fEof(nHnd)
-
- fClose(nHnd)
-
-
- return this
-
- Endclass
-
-