home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-12-20 | 53.0 KB | 2,155 lines |
- *********************************************************************
- Unit Tbase.TPU
- *********************************************************************
-
- Introduction
-
- This is the main unit of my goal- Defining Objects to handle Dbase III
- and FOXPRO compatible files.
-
- The old existing Programs did not provide satisfactory performance
- to me. Tbase provides facilities to Create Dbase files, Manipulation
- on FIeld Structure and Manipulations on Data.
-
- Tbase allows you to supply Fieldname as argument ( string ) in methods.
- For example, FieldData( 'Cust_No' ) will give you the data of CUST_NO
- in the current record ( if such a field exists.. )
-
- For those who are familiar with using Field numbers in the older
- programs, Tbase provide Methods that accepts field numbers too.
-
- The consistency in these procedures are: any method that accepts
- a field name string as an argument has its counterpart with the same
- structure but with Field number in place of Field Name.
- The name of the method adds a MY in its identifier.
- For example, FieldData accepts Field name string while MYFieldData accept
- Field Number as Argument.
-
- Validity Checks are performed in many methods. If the check fails
- anywhere, the error variable DbError is set to an error number and
- a Bleep sound occurs. No Screen Display is reported nor does the
- program abort. The only case the program is aborted is when
- initializing ( Opening ) a Dbase Object.
-
- The reason for this non-screen report is to avoid the disturbance
- when using graphical environment.
-
-
- Whenever the Dberror is set to a nonzero value ( due to an error )
- any other succeeding calls to any method will be ignored causing
- non-Update of your data or even loose.
-
- So, if your program does make a bleep anywhere, debug it and correct the
- problem. To refer the error and to know causing factor, Refer to the
- table below for meaning of the DbError values. A call to LastDbError
- will return the error value and Clears the DbError.
-
- Dberror is internal to Object. Hence an error in one Dbase object does
- not affect the other Dbase objects method call.
-
- DbError Error description
-
- 0 No Error.
- 1 Header Description corrupted.
- 2 Disk read Error.
- 3 Dbase File Not Found.
- 4 Not Enough Memory to allocate.
- 5 File Access Denied or could not open file.
- 6 Could not Write to disk.( Sector problem? Disk full?)
- 7 Field Type is not Numeric.
- 9 Field name does not exits or Field Number out of range.
- 8 Not valid date.
- 10 Data does not match with Field Type.
- 11 --
- 12 --
- 13 Could not Create file.
- 14 Dbase file Not Empty.
- 15 Invalid Field Type.
- 16 Field limit exceeds. Only 255 fields are allowed.
- 17 Divisor Field is zero.
-
- When I encounter more error situations, I will add more error values.
- If you find anything.. report them to me..please.
-
- *********************************************************************
- Tbase unit Procedures and Functions
- *********************************************************************
-
-
- Add, MyAdd
-
- Description
- Adds two numeric fields and returns real result.
-
- Syntax
- Function Add( Field1, Field2 : String) : Real;
- Function MyAdd( Fno1 , Fno2 : Byte ) : Real;
-
- Remarks
- Field1 and Field2 are the names of the fields.
- Exits with Bleep if Fields are not numeric and the result
- is set to zero.
-
-
- See Also
- Increment, Decrement, Multiply, Mul, Divide and their MYs
- ----------------------------------------------------------
-
- AddBlankRecs
-
- Description
- Appends a number of Blank records to the Dbase file.
-
- Syntax
- Procedure AddBlankRecs( NumRecs : LongInt);
-
-
-
- See Also
- AppendBlank , PutDbRec, ClearMemRec
- ----------------------------------------------------------
-
- AddDbRec
-
- Description
- Appends the Memory record to Dbase file.
-
- Syntax
- Procedure AddDbRec;
-
- Remarks
- The difference between AppendBlank and AddDbRec is that
- AddDbrec Dumps the memory record to file while AppendBlank
- Will clear the memory and writes to disk
-
- Warning
- If the memory record is marked for deletion,the added record
- is also written as marked. Undelete before writing.
-
- See Also
- AppendBlank, AddBlankRecs
- ----------------------------------------------------------
-
- AppendBlank
-
- Description
- Adds a Blank Record to Dbase file
-
- Syntax
- Procedure AppendBlank;
-
-
- Warning
- Memory Record will be lost.
-
- See Also
- AddBlankRecs
- ----------------------------------------------------------
-
- Average , MyAverage
-
- Description
- Calculates the Average of a numeric field
-
- Syntax
- Function Average(Field1 : String) : Real;
-
- Remarks
- Checks for Numeric type and for Number of records is > 0.
- If check fails Average is reset to 0.0 and bleeps
-
-
- See Also
- Sum , MySum
- ----------------------------------------------------------
-
- ChangeField , MyChangeField
-
- Description
- Changes the Description of a Field Structure on an EMPTY
- Dbase File.
-
- Syntax
- Procedure ChangeFIeld( Field1, Fname: String; Ftype: Char;
- Flen, Fdec : Byte );
-
- Remarks
- Memory record size is adjusted if needed. Checks for valid
- type Character. C,N,F,D,L are supported. Field length is
- automatic for D and L type. Ignores any length in this case
-
- Warning
- Maximum Field Length is 254. Though 255 is accepted, Foxpro
- and other Dbase KITs do not identify it as a Dbase File.
-
- See Also
- AddField, DeleteField, FieldName, FieldNo, FieldType
- ----------------------------------------------------------
-
- CopyStructureTo
-
- Description
- Creates another Empty Dbase File with the specified name
- copying the current file Structure.
-
- Syntax
- Procedure CopyStructureTo(Fname: String);
-
- Remarks
- Only the Header is copied. Not the Data of the Dbase file.
- The new Empty Dbase file must be explicitly opened for any
- addition of Data.
-
-
- See Also
- CreateDbaseFile, DeleteDbaseFile
- ----------------------------------------------------------
-
- ClearMemRec
-
- Description
- Clears the memory record by Space Characters.
-
- Syntax
- Procedure ClearMemRec;
-
- Remarks
- The old Memory record is written to the current record if
- Autosave is TRUE
-
-
- See Also
- AppendBlank
- ----------------------------------------------------------
-
- DbBof
-
- Description
- Return True if the current Record is the first or nil (in
- case of no record are found).
-
- Syntax
- Function DbBof : Boolean;
-
-
-
- See Also
- DbEof
- ----------------------------------------------------------
-
- DbDelete
-
- Description
- Marks the record as Deleted.
-
- Syntax
- Procedure DbDelete;
-
- Remarks
- Mark not written to file immediately. Autosave will do that.
- If Autosave is OFF, manually update the record to disk.
-
-
- See Also
- Recall , Pack, Zap
- ----------------------------------------------------------
-
- DbEof
-
- Description
- Returns TRUE if the current record is the last record
-
- Syntax
- Function DbEof : Boolean;
-
-
-
- See Also
- DbBof
- ----------------------------------------------------------
-
- DbfName
-
- Description
- Returns the Dbase filename opened in the object.
-
- Syntax
- Function DnfName : String;
-
- Remarks
- Only the name with extension is returned. not the path.
-
-
- See Also
- DbfDir
- ----------------------------------------------------------
-
- DbfDir
-
- Description
- Returns the Path of the Dbase file.
-
- Syntax
- Function DbfDir : String;
-
- Remarks
- Only the path that you have given when initializing the
- object is returned.
-
-
- See Also
- DbfName
- ----------------------------------------------------------
-
- Dbreset
-
- Description
- Resets the Dbase file as newly initialized.
-
- Syntax
- Procedure DbReset;
-
- Remarks
- Current record is set to 1 or 0 (if no data)
-
- Warning
- Memory record is lost if not written to file.
-
- See Also
- Init
- ----------------------------------------------------------
-
- Decrement , MyDecrement
-
- Description
- Subtracts a real value from a specified field and returns
- real result.
-
- Syntax
- Function Decrement( Field1: String; by : real ): Real ;
- Function MyDecrement(Fno: Byte; by : Real ) : Real ;
-
- Remarks
- Checks for Numeric fields and bleeps for warning.
- Negative values in 'by' will ( ofcourse ) be added.
-
- Warning
- Does not check for overflow.
-
- See Also
- Increment , add, Sub and their MY counterparts.
- ----------------------------------------------------------
-
- Deleted
-
- Description
- Returns True if the current record is marked for deletion
-
- Syntax
- Function Deleted : Boolean;
-
-
-
- See Also
- DbDelete, Recall , Pack, Zap
- ----------------------------------------------------------
-
- DeleteField, MyDeleteField
-
- Description
- Removes a field from the structure of an EMPTY Dbase file.
-
- Syntax
- Procedure DeleteField( Field1 : String );
- Procedure MyDeleteField( FNo : Byte );
-
- Remarks
- Field Numbering is reassigned bringing the later fields one
- step closer. Memory record size is adjusted. If field1 is
- not found Dberror is set to 9 ( Fieldno out of range )
-
-
- See Also
- AddField, ChangeField, CopyStructureTo, CreateDbaseFile
- ----------------------------------------------------------
-
- AddField, MyAddField
-
- Description
- Adds a new Field Description to the Dbase Structure.
-
- Syntax
- Procedure AddField(Fname:String; Ftype:Char;Flen,Fdec:Byte);
- Procedure MyAddfield(Fno:Byte;Ftype:Char; Flen,Fdec : Byte);
-
- Remarks
- Memory Record size is Adjusted. Checks for valid Fieldtype.
- Flen and Fdec are length and decimal sizes. Flen and Fdec
- are ignored for D,L type. Fdec is ignored for non-numeric.
-
- Warning
- Allowed number of Fields are 255. For Foxpro compatibility,
- keep the total record size not exceed 4000bytes.
-
- See Also
- ChangeField , DeleteField and their MY counterparts.
- ----------------------------------------------------------
-
- Divide, MyDivide
-
- Description
- Divides the first Numeric Field value by the second and
- returns real.
-
- Syntax
- Function Divide( Field1,Field2 : String) : Real ;
- Function MyDivide( Fno1, Fno2 : Byte ) : Real ;
-
- Remarks
- Checks whether the second field data is zero. If so, the
- result is set to 0.0. Checks also for numeric Data in both
- fields. Call LastDberror for error value.
-
-
- See Also
- Multiply, add, Sub and their MY variations
- ----------------------------------------------------------
-
- Done
-
- Description
- Closes the Dbase File and its Object.
-
- Syntax
- Destructor Done;
-
- Remarks
- Frees all the associated memory. Use it with dispose.
- Eg. Dispose( MyDbf , Done ) ;
-
- Warning
- If not used with Dispose, memories are not freed and the
- Dbase file is NOT closed causing loss of Data.
-
- See Also
- Init
- ----------------------------------------------------------
-
- FieldCount
-
- Description
- Returns the Number of Fields in the Dbase file.
-
- Syntax
- Function FieldCount : Byte;
-
-
-
- See Also
- FieldName, FieldNo, FieldSize, FieldType
- ----------------------------------------------------------
-
- FieldData, MyFieldData
-
- Description
- Returns the Data of the Specified field of current record.
-
- Syntax
- Function FieldData( Field1 : String ) : String ;
- Function MyFieldData(Fno : Byte ) : String ;
-
- Remarks
- If FIeld1 not found Dberror 9 is returned. Data is NOT
- Trimmed. Use Trim, Ltrim or Rtrim in DBStr which trims
- the trailing and leading spaces and nulls.
-
- Warning
- For Date field, the date is formatted according to the
- current format setting.
-
- See Also
- Replace , MyReplace
- ----------------------------------------------------------
-
- FieldName
-
- Description
- Returns the Name of the specified field number.
-
- Syntax
- Function FieldName(Fno : Byte ) : String;
-
- Remarks
- Checks for Fno range (1..FieldCount).
- FieldName Returned is Trimmed ( Unlike FIeldData ).
- Null String Returned if any failure to validity check.
-
- Warning
- Returned name is Upper cased. Eg. CUST_NO
-
- See Also
- FieldNo, FieldSize, FieldType, FieldCount
- ----------------------------------------------------------
-
- FieldNo
-
- Description
- Returns the Ordinal number of the Specified field name.
-
- Syntax
- Function FieldNo ( Field1: String ) : Byte ;
-
- Remarks
- Field1 can be of any case having trailing and leading spaces
- or nulls. The same theory applies to ALL methods having
- field name string as argument. eg. ' cUst_NO ' is valid.
-
- Warning
- 0 is returned if the name is not valid or not found in the
- structure.
-
- See Also
- FIeldName, FIeldSize, FieldType, FIeldCount
- ----------------------------------------------------------
-
- FieldSize, MyFieldSize
-
- Description
- Returns the Field length of an specified field name.
-
- Syntax
- Function FieldSize ( Field1 : String ) : Byte ;
- Function MyFIeldSize( Fno : Byte ) : Byte ;
-
-
- Warning
- 0 is returned if Field name or number is invalid.
-
- See Also
- FieldName, FieldType, FieldNo, FieldCount, FieldDec
- ----------------------------------------------------------
-
- FieldType, MyFieldType
-
- Description
- Returns the Type of the specified field Name or Number.
-
- Syntax
- Function FieldType( Field1 : String ) : Char ;
- Function MyFieldType(Fno : String ) : Char ;
-
- Remarks
- Returned Characters are : C - Character; N - Numeric
- F - Floating; D - Date; L - Logical; M - Memo.
-
- Warning
- Although 'M' is identified, no support is provided in this
- version.
-
- See Also
- FiledName, FieldSize, FieldNo, FieldCount, FieldDec
- ----------------------------------------------------------
-
- FlushDb
-
- Description
- Saves the Memory record to the current record.
-
- Syntax
- Procedure FlushDb;
-
- Remarks
- No need to use this if autosave is ON ( TRUE ).
-
- Warning
- Record in the current record is overwritten. (Who Cares !!)
-
- See Also
- PutDbRec, GetDbRec, SetAutoSave
- ----------------------------------------------------------
-
- GetDbRec
-
- Description
- Loads the specified recordNumber into memory record.
-
- Syntax
- Procedure GetDbRec( RecordNumber : LongInt) ;
-
- Remarks
- RecordNumber becomes current record. If AutoSave is ON,
- the previous memory is Flushed to its position if modified.
- Checks for Valid RecordNumber ( 1..RecCount )
-
- Warning
- Exception: Memory record is not updated when loading the
- same record.Eg. GetDbRec(RecNO) will cancel any last update.
-
- See Also
- FlushDb, PutDbRec, SetAutoSave
- ----------------------------------------------------------
-
- GetFieldHeaders ( Internal )
-
- Description
- Reads the Field header to memory ( not to Memory record )
-
- Syntax
- Procedure GetFieldHeaders;
-
- Remarks
- Use this if you feel the Field methods give improper results
- This will not happen anyway.. But just to be on safe side.
- I use this internally.
-
-
- See Also
- ReadHeader, WriteHeader, WriteFields ( all internal )
- ----------------------------------------------------------
-
- GoBottom
-
- Description
- Moves to the last record of the Dbase file and loads it into
- memory record.
-
- Syntax
- Procedure GoBottom;
-
- Remarks
- Ignores if No record found.Previous memory record is flushed
- if Autosave is ON.
-
- Warning
- If AutoSave is OFF, the prevoius memory is lost. Manually
- Flush the memory record if so.
-
- See Also
- GoTop, NextRec, PrecRec, Skip, Locate
- ----------------------------------------------------------
-
- GoTop
-
- Description
- Positions to the First record of the Dbase file and loads
- it into memory record.
-
- Syntax
- Procedure GoTop;
-
- Remarks
- Ignores if no record is found. Prevoius memory record is
- flushed if AutoSave is ON.
-
- Warning
- If Autosave is OFF, the prevoius memory record is lost.
- Manually Flush the memory record if so.
-
- See Also
- GoBottom, NextRec, PrevRec, Skip, Locate
- ----------------------------------------------------------
-
- Increment, MyIncrement
-
- Description
- Adds a real value to specified field data in the current
- record and returns real.
-
- Syntax
- Function Inrement( Field1 : String; By : Real ) : Real ;
- Function MyIncrement( Fno : Byte ; By : real ) : Real ;
-
- Remarks
- Field1 is the FieldName of the numeric field.'By' is the
- real value incremented.Ignores if FielName is not of Numeric
- type and returns 0 with error bleep.
-
-
- See Also
- Decrement, Add, Sub, SUM, Average, Mul, Multiply
- ----------------------------------------------------------
-
- Init
-
- Description
- Opens the Dbase file loading the necessary information into
- memory.
-
- Syntax
- Constructor Init( Fname : String66) ;
- Eg. NEW( MyDbf, init('MyDb.Dbf') );
-
- Remarks
- Allocates minimum memory to accommodate information.
- More fields means more memory.
-
-
- See Also
- Done
- ----------------------------------------------------------
-
- LastDbError
-
- Description
- Returns the Last Errorvalue occurred and clears it to zero.
-
- Syntax
- Function LastDberror : Byte ;
-
- Remarks
- Useful to check the error occurred. If the DBerror is not
- cleared by this call, All calls to any method will be
- ignored. This applies to all methods in the Object.
-
- Warning
- Exceptions are Init and Done.
-
- ----------------------------------------------------------
-
- Locate , MyLocate
-
- Description
- Sequentially Searches for a string in a specified field
- and loads the record into memory record if found.
-
- Syntax
- Procedure Locate(Field1: String; SearchStr : String );
- Procedure MyLocate(Fno : Byte ; SearchStr : String );
-
- Remarks
- The exact search string is searched for match with Trailing
- and leading spaces. If found, the record is loaded into
- memory and the Object local variable Found is set to TRUE.
-
- Warning
- If the field Data is filled with Null for trailing spaces,
- searching with Trailing spaces may not work.
-
- See Also
- GetDbRec
- ----------------------------------------------------------
-
- Lupdate
-
- Description
- Returns the Date that the Dbase file is Last modified.
-
- Syntax
- Function Lupdate : String;
-
- Remarks
- The Date Format is affected by the SetDateFormat in DbDate
- Unit. Refer DbDate unit procedures and function for allowed
- formats and Default format.
-
-
- ----------------------------------------------------------
-
- Mul, MyMul
-
- Description
- Multiplies two numeric fields and returns real.
-
- Syntax
- Function Mul(Field1, Field2: String ) : Real ;
- Function MyMul( Fno1, Fno2 : Byte ) : Real ;
-
- Remarks
- Checks for validity if Numeric Field type. Does Not Check
- for overflow. ( may be in future versions)
-
-
- See Also
- Add, Increment, Sub, Decrement, Divide, SUM, Average
- ----------------------------------------------------------
-
- Multiply, MyMultiply
-
- Description
- Multipies a Numeric FieldData with a real number and returns
- real.
-
- Syntax
- Function Multiply( Field1 : String; By : real ): Real;
- Function MyMultiply( Fno1 : Byte ; By : real ): Real;
-
- Remarks
- Checks for Numeric fields. Returns 0 if not valid. Does not
- check for Overflow.
-
-
- See Also
- Add, Increment, Decrement, Sub, Divide, Mul, SUM, Average
- ----------------------------------------------------------
-
- NextRec
-
- Description
- Moves to the next record and loads it into memory record.
-
- Syntax
- Procedure NextRec;
-
- Remarks
- If Autosave is ON the previous memory record is flushed.
-
-
- See Also
- Skip, PrevRec, GoTop, GoBottom
- ----------------------------------------------------------
-
- Pack
-
- Description
- Removes all the marked records for deletion. You no longer
- have any deleted records.
-
- Syntax
- Procedure Pack;
-
- Remarks
- Current record is pointed to the last record.
- Ignores if no record is found deleted ( Ofcourse !)
- Slow as complete read-write occurs.
-
- Warning
- Memory record will be lost if AutoSave is OFF.
- No recovery possible after packed.
-
- See Also
- Zap, DbDelete, Recall
- ----------------------------------------------------------
-
- PutDbRec
-
- Description
- Writes the memory record to specified recordNumber.
-
- Syntax
- Procedure PutDbRec( RecordNumber : LongInt );
-
- Remarks
- Different than FlushDB in the sense that it writes the
- memory record to a different location. Flushes the previous
- memory record to its position if changed.
-
- Warning
- If the memory record is marked for deletion it is written as
- deleted. Recall if you want to.
-
- See Also
- GetDbRec, FlushDb
- ----------------------------------------------------------
-
- PrevRec
-
- Description
- Moves to the previous record and loads it into memory record
-
- Syntax
- Procedure PrevRec;
-
- Remarks
- Ignores if no record found.Previous memory record is written
- to its position if Autosave is ON.
-
-
- See Also
- NextRec, Skip, GoTop, GoBottom
- ----------------------------------------------------------
-
- Recall
-
- Description
- Undeletes the current record if marked.
-
- Syntax
- Procedure Recall;
-
- Remarks
- Does not immediately writes to file. When moving to another
- record, memory is flushed if autosave is ON.
-
- Warning
- If AutoSave is OFF, manually Flush the memory record.
-
- See Also
- DbDelete, Pack
- ----------------------------------------------------------
-
- RecCount
-
- Description
- Returns the Number of Records in the DBase file.
-
- Syntax
- Function RecCount : LongInt ;
-
-
-
- See Also
- RecNo
- ----------------------------------------------------------
-
- RecNo
-
- Description
- Returns the Current record number positioned.
-
- Syntax
- Function RecNo : LongInt;
-
-
-
- See Also
- RecCount , FieldCount
- ----------------------------------------------------------
-
- RecSize
-
- Description
- Returns the Record size of a record in Dbase.
-
- Syntax
- Function RecSize : word;
-
- Remarks
- This size will be adjusted if field structure is modified
- by addfield, changefield or deletefield.
-
- Warning
- If Recsize >4000 bytes, the Dbase file will NOT be Dbase III
- and foxPro compatible. But Tbase3 will recognize.
-
- ----------------------------------------------------------
-
- ReadHeader ( Internal )
-
- Description
- Reads the Header description of the Dbase file.
-
- Syntax
- Procedure ReadHeader;
-
- Remarks
- Checks for valid Header. I use this Internally.
-
-
- See Also
- ReadFieldHeaders, WriteHeader, WriteFields
- ----------------------------------------------------------
-
- Replace, MyReplace
-
- Description
- Replaces a FIeldData with a Formatted string Data.
-
- Syntax
- Procedure Replace( Field1: String; InData : String );
- Procedure MyReplace(Fno : Byte ; InData : String );
-
- Remarks
- This is the comprehensive replace for all type of fields.
- Checks if the Type fits with the Indata format.For dateType,
- Checks for valid date also. Numeric are reformatted to fit.
-
- Warning
- Date field requires a formatted date String according to the
- current format setting.
-
- See Also
- ReplaceAll, ReplNum, ReplDate, ReplStr and their MY versions
- ----------------------------------------------------------
-
- ReplaceAll, MyReplaceAll
-
- Description
- Replaces all records' in specified field with indata string.
-
- Syntax
- Procedure ReplaceAll(Field1: String; Indata : String );
- Procedure MyReplaceAll(Fno1: Byte ; Indata : String );
-
- Remarks
- Comprehensive as Replace. See description for replace above.
- Checks for valid field to match data. Numeric data is
- reformatted to fit with fieldlen and fieldDec.
-
- Warning
- Date Format requirs a formatted Date string.
-
- See Also
- Replace, ReplNum, ReplDate, ReplStr and their MY versions
- ----------------------------------------------------------
-
- ReplNum, MyReplNum
-
- Description
- Replaces a Numeric Field data with a real number.
-
- Syntax
- Procedure ReplNum( Field1 : String; Re : real ) ;
- Procedure MyReplNum( Fno1 : Byte ; Re : real ) ;
-
- Remarks
- Checks for Numeric field type, Formats the Real number
- according to fieldsize, and field Decimal.
-
- Warning
- Some Decimal accuracy maybe lost if the integral part of the
- number is beyond the limit.
-
- See Also
- Replace, ReplDate, ReplStr, ReplaceAll and their MY versions
- ----------------------------------------------------------
-
- ReplDate, MyReplDate
-
- Description
- Replaces a Date field with the Indate Data.
-
- Syntax
- Procedure ReplDate(Field1 : String; Indate : Date ) ;
- Procedure MyReplDate(Fno1 : Byte ; InDate : Date ) ;
-
- Remarks
- Date Datatype is defined in DbDate. Checks for valid Date
- and Date FieldType. Ignores if Fails. Formats the Date to
- the Date String form for the date field.
-
- Warning
- Year in Date record type MUST be in ccxx form. eg. 1993
-
- See Also
- DbDate Unit
- ----------------------------------------------------------
-
- ReplStr, MyReplStr ( Internal)
-
- Description
- Replaces ANY field by a String data.
-
- Syntax
- Procedure ReplStr( Field1: String; Instr : String );
- Procedure MyReplStr(Fno1 : Byte ; Instr : String );
-
- Remarks
- No checking is done during the replace. Only it trims the
- instr to fit with the Fieldsize. Use Replace if you want to
- replace string fields.
-
- Warning
- Do not use this as you might write wrong Data into a wrong
- FieldType. Internal
-
- See Also
- Replace, ReplaceAll, ReplNum, ReplStr
- ----------------------------------------------------------
-
- Save
-
- Description
- Writes all the appropriate memory date to file.
-
- Syntax
- Procedure Save;
-
- Remarks
- Almost like flush. But writes the header also.
- Only for security reason if you are
- aware of any power failure.
-
-
- See Also
- FlushDb
- ----------------------------------------------------------
-
- Skip
-
- Description
- Moves to the next record and loads it into memory.
-
- Syntax
- Procedure Skip;
-
- Remarks
- Excactly the same as NextRec. Just to make our old Dbase
- fans happy!.
-
-
- See Also
- NextRec, prevRec, GoTop, GoBottom
- ----------------------------------------------------------
-
- Sub, MySub
-
- Description
- Subtracts Field2 Numeric data from Field1 Numeric Data and
- returns real.
-
- Syntax
- Function Sub(Field1, field2 : String ) : Real ;
- Function MySub(Fno1, Fno2 : Byte ) : Real;
-
- Remarks
- Checks for Numeric fields. Ignores if either one fails and
- returns zero.
-
-
- See Also
- Add, Mul, Divide , Inrement, Decrememnt, SUM, Average
- ----------------------------------------------------------
-
- SUM , MySUM
-
- Description
- Adds all the data in the specified Numeric field and returns
- real.
-
- Syntax
- Function SUM ( Field1 : String ) : Real ;
- Function MySUM( Fno1 : Byte ) : Real ;
-
- Remarks
- Checks for Numeric Field Type. Ignores if not and returns 0
- as result. Does NOT check for overflow. ( In the future )
-
-
- See Also
- Add, Sub, Mul, Divide, Increment, Decrement, Average
- ----------------------------------------------------------
-
- WriteHeader ( internal )
-
- Description
- Writes the Header to Dbase file.
-
- Syntax
- Procedure WriteHeader;
-
- Remarks
- Last modified date is updated with the header.
-
-
- See Also
- Readheader, WriteFields, GetFieldHeaders
- ----------------------------------------------------------
-
- WriteFields ( internal )
-
- Description
- Writes the field structure description to the disk.
-
- Syntax
- Procedure WriteFields;
-
-
-
- See Also
- GetFieldHeaders
- ----------------------------------------------------------
-
- Zap
-
- Description
- Erases all data in the Dbase file.
-
- Syntax
- Procedure Zap;
-
- Remarks
- Permanently erases all data in the file.
- Complete recovery is not possible. A partial recovery is
- tried in this version.
-
- Warning
- Think Twice before you Zap!!
-
- See Also
- Pack, Recover
- ----------------------------------------------------------
-
- DisplayFields
-
- Description
- Just Displays the fieldnames on the screen for reference.
-
- Syntax
- Procedure DisplayFields;
-
- Remarks
- Not much format is is provided as display is NOT the purpose
- of the Object. Use FieldName, FieldNo, FieldType, FieldSize
- and FieldDec for field description detail
-
- Warning
- Does not display in Graphical environment.
-
- See Also
- FieldName, FieldSize, FieldType, FieldNo, FieldDec
- ----------------------------------------------------------
-
- FieldDec , MyFieldDec
-
- Description
- Returns the Decimal value of a Numeric field.
-
- Syntax
- Function FieldDec (Field1: String ) : Byte ;
- Function MyFieldDec( Fno : Byte ) : Byte ;
-
- Remarks
- Zero is returned if the Field Type is not Numeric.
-
-
- See Also
- FieldName, FieldSize, FieldType, FieldNo, FieldCount
- ----------------------------------------------------------
-
- Autosaved ( Internal )
-
- Description
- Flushes the memory record whenever needed if Autosave is ON.
-
- Syntax
- Procedure Autosaved;
-
- Remarks
- It writes the memory record to file only if any changes have
- been made since last flush or load. This minimizes the disk
- write when autosave is ON.
-
-
- See Also
- SetAutosave
- ----------------------------------------------------------
-
- SetAutoSave
-
- Description
- Sets the autosave status to ON or OFF.
-
- Syntax
- Procedure SetAutosave( auto : Boolean ) ;
-
- Remarks
- If auto is TRUE, Autosave is set to ON otherwise OFF.
- Default is ON.
-
- Warning
- If autosave is set to OFF, any update to memory record MUST
- be manually saved to file.
-
- ----------------------------------------------------------
-
- *********************************************************************
- Unit DbEdit
- *********************************************************************
- Introduction
-
- This unit handles the field and variable editing. GET and MyGET
- prepares for editing of a dbase file fields while SAY prepares
- for a variable edit. All these three procedures can be mixed in
- a group of Editing. Dbread activates the editing.
-
- Dbread Updates the Fields automatically upon completing its job.
- If the fields are from different Dbase files, they are updated
- accordingly. Variables are kept in their names.
-
- Each edit item can have its own color. Just set the edit color
- for the next item by SetEditColor.
-
- Each Edit item can have its own help too. All you have to do is to
- write a FAR rpocedure that displays Help or anything you want.Then,
- Set the help procedure through SetHelpProc for the next edit item.
- Preesing F1 will call the assigned procedure. It is your responsibility
- to add fancy in that procedure. Eg. Open a winodow and close it.
- See My.Pas.
-
- The help procedure has no argument and ofcourse should
- be a far {$F+} procedure {$F-}.
- If no help is needed for an Item, Use SetHelpProc ( NoHelp ) ;
-
- If Crtl_Brk is pressed, Dbread simply exits the editing without
- updating the Fields. But Variables (SAY) have the effect of change.
-
- Field Type, Length and Field Decimal ( for numeric ) are needed for
- SAY to identify the editing behaviour. Use SetEditDecimal to Set
- decimal before calling SAY With numerical String.
-
- MYGET and GET assume their field type and decimal values from the field
- being editted. No Picture support is provided for now. ( Too much to ask )
- DbEdit checks for the validity of the data for its type.
-
-
- Upon completing the edit, DbEdit sets a variable ReadExitCode a value
- according to the circumstance of the Exit. Different key press gives
- different values for ReadExitcode. This could be refered to take action
- according to the keypress.
-
- Following are the Keys and ReadExitCode for DbRead.
-
- Key ReadExitCode
-
- F10 3
- PgUp 4
- PgDn 5
- Alt_X 6
- Ctrl_N 7
- Ctrl_Brk 8
- Ctrl_PgUp 9
- Ctrl_PgDn 10
- Ctrl_X 11
- Ctrl_End 12
-
- Dbedit is exitted in either of the situations.
-
- 1. Pressing Enter when editting the last field or variable.
- ( ReadExitCode = 0 )
- 2. Pressing Down arrow key when editing the last field or var
- ( ReadExitCode = 2 )
- 3. Pressing any of the keys above from anywhere in editting.
- ( ReadexitCode as above)
-
- See my.Pas for how these exitcodes are used to take action.
-
-
- *********************************************************************
- Set_Cursor
-
- Description
- Sets the Cursor size to specified size from bottom.
-
- Syntax
- Procedure Set_Cursor( n : Byte ) ;
-
-
- ----------------------------------------------------------
-
- SetEditColor
-
- Description
- Sets the editing color pair for field line editor.
-
- Syntax
- Procedure SetEditColor( fcolor , bcolor : byte );
-
- Remarks
- fcolor is the forground color and bcolor is background.
- Every field edit can have its own color pair. Just set the
- color just before a call to SAY.
-
-
- See Also
- Say , Dbread
- ----------------------------------------------------------
-
- Arrow
-
- Description
- Reads a keypress and return ascii and scan code.
-
- Syntax
- Procedure Arrow( Var Ascii , scan : Byte );
-
- Remarks
- Ctrl_Brk has no effect. But Returns Ascii = 3 and scan = 0.
-
-
- ----------------------------------------------------------
-
- edit ( internal )
-
- Description
- Allows Editing of a string variable.
-
- Syntax
- Function Edit(var Item : ReaderPtr ) : Word ;
-
- Remarks
- Returns various code values depending on the exit key.
- The standard editing keys have their own function. See
- My.Pas for more detail. Allows Editing according to Type.
-
- Warning
- When Date Field is editted, leaving the date Blank will
- replace the System Todays Date.
-
- See Also
- Say, DBread
- ----------------------------------------------------------
-
- Say
-
- Description
- Prepares a variable for editing. Say is not a displayer.
- Differ With GET in Say only edits Variable. NOT fields.
-
- Syntax
- Procedure Say( x , y , Len : Word; s : PtrStr;
- Ftype : FieldTypes);
-
- Remarks
- x,y is the starting position, Len is the length of string,
- s is the POINTER to the editted string variable.Eg @name
- Ftype is the type of variable to treat as a field type.
-
- Warning
- Decimal size for Numeric type must be set through
- SetEditDecimal.
-
- See Also
- Get, DbRead
- ----------------------------------------------------------
-
- Dbread
-
- Description
- Activates all the variables prepared for ediitting by SAY
- , GET and MyGET
-
- Syntax
- Procedure Dbread;
-
- Remarks
- Called once for a group of SAYs and GETs.Checks for validity
- of Data for FieldType. Does not allow moving to next field
- if the check fails.
-
- Warning
- Exits for many key combinations with various ReadEditCode.
- See my.Pas for more detail.
-
- See Also
- Say
- ----------------------------------------------------------
-
- SetHelpProc
-
- Description
- Sets a procedure for an edit field for Help.
-
- Syntax
- Procedure SetEditProc( Help : HelpProc );
-
- Remarks
- HelpProc is a Far procedure type with no arguments.
- You can assign help to each editted fields. See My.Pas.
- Default is NoHelp
-
- Warning
- If your HelpProcedure allocates any memory, make sure to
- deallocate them before exiting.
-
- See Also
- NoHelp
- ----------------------------------------------------------
-
- NoHelp
-
- Description
- A null Help Procedure that does nothing.
-
- Syntax
- {$F+} Procedure NoHelp; {$F-}
-
- Remarks
- This is the Default Help procedure. An assignment to a user
- defined help procedure will be effective until it turned off
- Use SetHelpProc(Nohelp) to get back to Default.
-
-
- See Also
- SetHelpProc
- ----------------------------------------------------------
-
- Get
-
- Description
- Prepares a Field of a Dbase File for editting.
- Handles Multiple Dbase files' Fields together.
-
- Syntax
- Procedure GET(x, y: Word; DbObj: DataObject; Field: String);
-
- Remarks
- DbObj is the pointer to the Dbase object. 'Field' is a Fiel
- in that object. You can give different Dbobj in a group of
- editting. They will be updated accordingly. Clever.. huh..
-
- Warning
- If the Field name is not valid, a bleep warns. Take care at
- this point as the data will not be updated in this case.
-
- See Also
- SAY , DbRead
- ----------------------------------------------------------
-
- MyGET
-
- Description
- Prepares a Field for Editting and updates to the proper data
- base file when editting finishes.
-
- Syntax
- Procedure MyGET ( x,y, Dbase : DataObject ; Fno : Byte );
-
- Remarks
- This is just the My version of GET for those who uses the
- Field Number instead of FieldName itself. Or in otherwords,
- All the MY Versions are the TPDB fans.
-
- Warning
- If the Fno is out of range then the data will not be updated.
- ( Where to update? ) Thus you loose the editted data.
-
- See Also
- SAY , GET DbRead
- ----------------------------------------------------------
-
- ***********************************************************************
- Unit DbDate.TPU
- ***********************************************************************
-
- Introduction
-
- This unit performs most of the operations on date.
-
- Conversion between the three type of date formats are provided.
- Thse three fields are:
-
- Field : The format that the Dbase file have date as Data.
- field format is of the form 'ccyymmdd'. eg. 19921223
- Display : The format for display. This has many forms according
- to country. Following are the formats supported in this
- unit.
-
- French : dd/mm/yy
- German : dd.mm.yy
- Italian : dd-mm-yy
- British : dd/mm/yy
- American : mm/dd/yy
- Ansi : yy.mm.dd
-
- Pascal : The pascal format is the record containing the
- three fields Year, month and day with year in 19yy.
- Date = Record
- Year, Month , Day : Word ;
- End;
-
- I name Field for Field format;
- Format for Display format;
- Date for Pascal format to name the convertion procedures.
-
- Thus, FieldToFormat will convert the filed format to Display format;
- DateToField wil convert the Pascal format to Field Format
- and so on.
-
- SetDateFormat will set the current display format.
-
-
- ***********************************************************************
- Julian
-
- Description
- Returns the classic Julian number of a Date.
-
- Syntax
- Function Julian ( d : Date ) : LongInt;
-
- ----------------------------------------------------------
-
- DaysBetween
-
- Description
- Returns the number of days between two dates.
-
- Syntax
- Function DaysBetween( d1, d2 : Date ) : LongInt;
-
-
- Warning
- Negative days are reported if d2 is earlier d1.
-
- See Also
- DateAfter
- ----------------------------------------------------------
-
- MDY
-
- Description
- Formats a date to Month dd, 19yy format
-
- Syntax
- Function MDY( d : Date ) : String ;
-
- Remarks
- Example. const d : date = ( Year: 1992; Month:11; day:28);
- Begin Writeln( MDY( d ) ) End.
- result: November 28, 1992
-
-
- See Also
- DateFormat
- ----------------------------------------------------------
-
- DateToField
-
- Description
- Converts a date to a Dbase Date Field String type.
-
- Syntax
- Function DateToField( d : Date ) : String;
-
- Remarks
- The Dbase Date Format is : 19yymmdd
-
- Warning
- Checks valid date. Nul string returned if fails.
-
- See Also
- FieldToDate
- ----------------------------------------------------------
-
- DateToFormat
-
- Description
- Formats a Date to a string format for display.
-
- Syntax
- Function DateToFormat( d : Date ) : Str8 ;
-
- Remarks
- The format wanted is selected through SetDateFormat.
-
-
- See Also
- DateToField, FieldToDate, FormatToDate, FieldToFormat
- ----------------------------------------------------------
-
- SetDateFormat
-
- Description
- Sets the default date format for conversion.
-
- Syntax
- Procedure SetDateFormat( form : Byte ) ;
-
- Remarks
- Any conversion the returns or involves formatted date is
- affected by the current format. In Tbase unit, FieldData,
- Replace are affected. SAY in Dbedit is also affected.
-
- See Also
- FormatToDate, FormatToField, FieldToFormat, DateToFormat
- ----------------------------------------------------------
-
- FieldToDate
-
- Description
- Converts a Dbase Date Format to a Pascal Date type.
-
- Syntax
- Procedure FieldToDate( s : String; Var d : date );
-
- See Also
- DateToField
- ----------------------------------------------------------
-
- DayofWeek
-
- Description
- Returns the Day of week in number for the specified date
-
- Syntax
- Function DayOfweek( d : Date ) : Word;
-
- Remarks
- The returned number is between 0 and 6 with 0 for Sunday.
-
-
- See Also
- NameOfWeek
- ----------------------------------------------------------
-
- NameOfWeek
-
- Description
- Returns the name of week for the day.
-
- Syntax
- Function NameOfWeek( d : date ) : Str10 ;
-
- Remarks
- Sunday, Monday.. Etc
-
-
- See Also
- DayOfWeek
- ----------------------------------------------------------
-
- DateAfter
-
- Description
- Returns the date after a certain days
-
- Syntax
- Procedure DateAfter( Var D : Date; days : LongInt );
-
- Remarks
- Negative days willadvance the date as usual
-
- Warning
- The previous date will be lost. Be careful.
-
- ----------------------------------------------------------
-
- Today
-
- Description
- Returns the Date of the System Clock in Date type
-
- Syntax
- Procedure Today ( Var d : day );
-
-
-
- ----------------------------------------------------------
-
- ValidDate
-
- Description
- Checks for the validity of a date and returns TRUE if valid.
-
- Syntax
- Function ValidDate( d : Date ) : Boolean ;
-
-
-
- ----------------------------------------------------------
-
- FormatToDate
-
- Description
- Converts a formatted date to a Pascal date.
-
- Syntax
- Procedure FormatToDate( form: String;Var d : Date);
-
- Remarks
- Form is assumed to be a formatted date according to the
- current Date format set through SetDateFormat.
-
-
- See Also
- DateToFormat, FormatToField
- ----------------------------------------------------------
-
- FieldToFormat
-
- Description
- Converts a Dbase Date format to Display Date format
-
- Syntax
- Function FieldToFormat( Fielddate : String) : String;
-
- Remarks
- Returned format is affected by Current format set through
- SetDateFormat.
-
-
- See Also
- FormatToField
- ----------------------------------------------------------
-
- FormatToField
-
- Description
- Converts a Display Date Format to a Dbase Date Format.
-
- Syntax
- Function FormatToDate( Form : String ) : String;
-
- Remarks
- Form is a formatted Date String according to the current
- SetDateFormat.
-
-
- See Also
- FieldToFormat
- ----------------------------------------------------------
-
- DaysFromZero ( Internal )
-
- Description
- Returns the number of days from a certain date.
-
- Syntax
- Function DaysFromZero( d : Date ) : LongInt;
-
- Remarks
- This is the serial day from the given date. This is 1721119
- days Less than the classical Julian Date.
-
-
- See Also
- Julian
- ----------------------------------------------------------
-
- **********************************************************************
- Unit DbStr.TPU
- **********************************************************************
-
- Introduction
-
- String manipulations are done in this unit along with the three
- sound procedures: Beep, bleep and warnerror. ( Why wasting another unit for
- these? )
-
- Ltrim, Rtrim and Trim are used to delete the trailing and leading
- spaces and Nulls.
-
- Upper converts a string to Uppercase.
-
- Thats it..
-
- **********************************************************************
-
- Beep
-
- Description
- Beeps a sound with the specified frequency
-
- Syntax
- Procedure Beep(Frequency : word);
-
-
-
- See Also
- Bleep, Warnerror
- ----------------------------------------------------------
-
- Bleep
-
- Description
- Beeps twice with different frequency ( 1000, 2000 )
- making a Bleep
-
- Syntax
- Procedure Bleep;
-
-
-
- See Also
- Warerror, Beep
- ----------------------------------------------------------
-
- WarnError
-
- Description
- Bleeps if the argument is non zero.
-
- Syntax
- Procedure WarnError ( Error : byte );
-
- Remarks
- Good to add with procedures that might have errors at
- anytime.
-
-
- See Also
- Beep , Bleep
- ----------------------------------------------------------
-
- Fileexists
-
- Description
- Checks whether the specified file exist in the directory or
- not. Rturns TRUE if exists.
-
- Syntax
- Function Fileexists( Fname : String) : Boolean;
-
-
- Warning
- Does not Search for file in any path.
-
- ----------------------------------------------------------
-
- Rtrim
-
- Description
- Trims the specified string from right. ( trailing )
- and returns the trimmed string.
-
- Syntax
- Function Rtrim( s : String ) : String ;
-
- Remarks
- Spaces( 32 ) and Nulls ( 0 ) on the right are trimmed.
-
- Warning
- Ignores if string is NUL ( '' ).
-
- See Also
- Ltrim, Trim
- ----------------------------------------------------------
-
- Ltrim
-
- Description
- Trims the leading spaces from the specified string and
- returns string.
-
- Syntax
- Function Ltrim ( s : String ) : string ;
-
- Remarks
- Spaces and nulls are trimmed.
-
-
- See Also
- Rtrim, Trim
- ----------------------------------------------------------
-
- Trim
-
- Description
- Trims a string from Both side.
-
- Syntax
- Function Trim ( s : String ) : String ;
-
- Remarks
- This is the combination of bothe Ltrim and Rtrim.
- i.e. Trim (s) := Ltrim( Rtrim(s)) ;
-
-
- See Also
- Ltrim , Rtrim
- ----------------------------------------------------------
-
- NumValid
-
- Description
- Checks whether a Numeric String is valid or not. If valid
- the value is returned in Re else Re is set to zero.
-
- Syntax
- Function NumValid( s : String; Var Re : Real ) : Boolean ;
-
- Remarks
- This is used to check the validity of the Numeric string in
- replace in Tbase.
-
- Warning
- Unlike in Pascal Val procedure, Spaces in Both sides are
- allowed here. Do NOT waste your code trimming before call.
-
- ----------------------------------------------------------
-
- NumFormat
-
- Description
- Formats a real number with specified size and decimals and
- return string.
-
- Syntax
- Function NumFOrmat( re : Real; Len, Deci : Integer ):String;
-
- Remarks
- Used in Replace method to format numeric data in Tbase.
-
- Warning
- Only 11 digits of decimals are significant in Deci.
-
- See Also
- Cstr
- ----------------------------------------------------------
-
- Cstr
-
- Description
- Formats a real number as in NumFormat and fills the spaces
- by '0'.
-
- Syntax
- Function Cstr( Re : Real; Len,Dec : Integer ) : String;
-
- Remarks
- Used to format Date string with leading zeros.
- eg. month = 03.
-
-
- ----------------------------------------------------------
-
- Upper
-
- Description
- Converts the specified string to upper case.
-
- Syntax
- Function Upper ( s : string ) : String ;
-
- ----------------------------------------------------------
- ***********************************************************************
- Unit DbWin.TPU
- ***********************************************************************
-
- Introduction
-
- Just some simple text windowing routines. Frankly, I am not interested
- in Text mode windowing. So any inconvenience is upto you. The routines
- are modifications of TP 6.0 examples Win.Pas and WinDemo.Pas.
- So, anyone asking the source code of all my units will not be given
- the codes of Dbwin. Sorry!.. Ask Borland.
-
- InitWindow initializes the windowing variables along with filling
- the screen with a block character. The colors are limitted in this
- desktop. Soory.. I am not that intersted to develop it more. I am
- doing somethign in Graphics now..
-
- ************************************************************************
-
- InitWindow
-
- Description
- Initializes the window variables and fill the screen with
- a block chracter making a DeskTop look.
-
- Syntax
- Procedure InitWindow( s : String );
-
- Remarks
- String s is displayed on the top line of the screen as a
- heading. Use WriteHeader for a centered Heading.
-
-
- See Also
- WriteHeader, WriteFoot, OpenWindow
- ----------------------------------------------------------
-
- OpenWindow
-
- Description
- Opens a window on the screen with Title and Foot.
-
- Syntax
- Procedure OpenWindow( x,y,x1,y1: Byte; Title, foot : String;
- Framecol, wincol : Word );
-
- Remarks
- (x,y) ,(x1,y1) are the topleft and bottomright corners.
- Title is displayed in middle of top border.Foot is displayed
- on the right bottom. Framecol and wincol are colors to win.
-
- Warning
- Allowed values for (x,y) and (x1,y1) are (0,0) to (79,24)
-
- See Also
- CloseWindow
- ----------------------------------------------------------
-
- CloseWindow
-
- Description
- Closes the recent window on the stack.
-
- Syntax
- Procedure CloseWindow;
-
- Remarks
- The topmost window is closed and its allocated memory is
- released. The next window becomes active with double line
- border.
-
-
- See Also
- OpenWIndow
- ----------------------------------------------------------
-
- CursorOff
-
- Description
- Turns text the cursor OFF ( invisible )
-
- Syntax
- Procedure CursorOff;
-
-
-
- See Also
- CursorOn
- ----------------------------------------------------------
-
- CursorOn
-
- Description
- Turns the cursor ON ( Blinking )
-
- Syntax
- Procedure CursorOn;
-
-
-
- See Also
- CursorOff
- ----------------------------------------------------------
-
- WriteHeader
-
- Description
- Writes the heading in the Top line of the screen.
-
- Syntax
- Procedure WriteHeader( s : String );
-
- Remarks
- Directly writes on the screen memory thus independent of any
- windows. Colors is taken from Crt ( TextAttr )
- Text is centered.
-
- Warning
- If Length(s) is > 80, s is trimmed to fit.
-
- See Also
- WriteFoot
- ----------------------------------------------------------
-
- WriteFoot
-
- Description
- Writes a foot note on the DeskTop.
-
- Syntax
- Procedure WriteFoot( s : String );
-
- Remarks
- Window independent. Colors is taken from TextAttr.
- Text is Left adjusted. Add spaces to make alligned.
-
- Warning
- Trimmed to fit the line.
-
- See Also
- WriteHeader.
- ----------------------------------------------------------
-
- DispWline
-
- Description
- Writes a string on the screen through direct memory access.
-
- Syntax
- Procedure DispWline( r, c, col : word ;var s : string );
-
- Remarks
- Window Independant.
-
-
- ----------------------------------------------------------
-
-
-
- Nasir Haniffa ( ACDH083@SAUPM00.BITNET )
-