home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / MISCTI10.ZIP / TI173.ASC < prev    next >
Encoding:
Text File  |  1988-04-18  |  6.6 KB  |  155 lines

  1. PRODUCT : TURBO DATABASE TOOLBOX     NUMBER : 173
  2. VERSION : 1.01
  3.      OS : PC-DOS, MS-DOS
  4.    DATE : May 14, 1986
  5.  
  6.   TITLE : FILES OPEN INCREASE 
  7.  
  8. written by 
  9.    Randy Forgaard CompuServe 70307,521
  10. Many   thanks  to  Bela  Lubkin,   (CompuServe  76703,3015)   for 
  11. masterminding this idea, and Kim Kokkonen (CompuServe 72457,2131) 
  12. for  helping debug it.   If you have any questions  or  comments, 
  13. regarding  the  following changes,  please feel free  to  contact 
  14. Randy Forgaard, on the Borland SIG or via EasyPlex on CompuServe.
  15.  
  16. Due to a limitation of DOS, Turbo Pascal, version 3.0 only allows  up to 15 files at a time to be open.  The following method allows  you  to have up to 96 files open simultaneously under DOS 2.0  or  2.1, or 252 files open simultaneously under DOS 3.0 or greater.
  17.  
  18. This  file is for use with the Turbo Access portion of the MS-DOS  Turbo Database Toolbox,  version 1.01 or greater,  together  with  MS-DOS or PC-DOS Turbo Pascal,  3.01A.  If you have 1.00 of Turbo  Database Toolbox contact Borland International for a handout that  will update the Turbo Database Toolbox to version 1.01.  
  19.  
  20. This technique is totally internal to the  Toolbox.  After making  the  indicated Toolbox changes,  you will not have to change  the  source  code  of programs that use the Toolbox (except to  add  a  compiler directive and an include file as indicated below).
  21.  
  22.  
  23. For  more discussion of Handle Tables and the  implementation  of  DOS  redirection,   please  see  Stan  Mitchell,   "Command  Line  Redirection," PC Tech Journal, January 1986, Page 44.
  24.  
  25. MODIFYING ACCESS.BOX:
  26.  
  27. Check  the comment header at the beginning of the file to  ensure  you are using the correct ACCESS.BOX.  Please BE SURE to make all  modifications on a backup copy of the ACCESS.BOX file.
  28.  
  29. NOTE:  If  you have modified ACCESS.BOX per FLUSH.ACC,  make  the 
  30.        following additional changes:
  31.  
  32. 6. In FlushFile:
  33. ----------------
  34.  
  35. Add  the  following  line  immediately  BEFORE  the  "Seek(...);" 
  36. statement:
  37.   UnExtend(DatF.F);
  38.  
  39. Add the following line immediately after the FIRST  "MsDos(...);" 
  40. statement:
  41.   ReExtend(DatF.F);
  42.  
  43.  
  44. 7. In FlushIndex:
  45. -----------------
  46.  
  47. Add  the  following  line  immediately  BEFORE  the  "Seek(...);" 
  48. statement:
  49.   UnExtend(IdxF.DataF.F);
  50.  
  51. Add  the  following line immediately after the  "BlockWrite(..);" 
  52. statement:
  53.   ReExtend(IdxF.DataF.F);
  54.  
  55.  
  56.  
  57. and  make sure that it is on your main program disk when you  run 
  58. your program.  
  59.  
  60. {$F252}
  61.  
  62. const
  63.   LastHandle = 19;    {Highest-numbered handle}
  64.   UnusedHandle = $FF; {DcbTable entry that denotes an unused handle}
  65. type
  66.   HandleTable = array[0..LastHandle] of Byte;
  67.   HandleTablePtr = ^HandleTable;
  68. const
  69.   TablePtrOk: Boolean = false; {"True" iff TablePtr is initialized}
  70. var
  71.   TablePtr: HandleTablePtr; {Points to Handle Table for this process}
  72.   SaveDcb:  Byte;  {Temporary  variable for a DCB number during a 
  73.                    function call}
  74.  
  75.  
  76. {Internal  routine.   Returns  the address of the  Handle  Table, 
  77. which is at offset 18H in the PSP.}
  78.  
  79. function GetHandleTableAddr: HandleTablePtr;
  80. var
  81.   regs: record
  82.           case Integer of
  83.             1: (AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags: Integer);
  84.             2: (AL, AH, BL, BH, CL, CH, DL, DH: Byte)
  85.           end;
  86. begin
  87.   regs.AH := $30;
  88.   MsDos(regs);         {Get DOS version number}
  89.   case regs.AL of
  90.     0: begin
  91.           writeln('This program only works with DOS 2.0 and higher');
  92.           Halt
  93.        end;
  94.     2: regs.AH := $51; {Undocumented, but works with}
  95.                        {DOS 2.0/2.1 (and 3.X)}
  96.   else regs.AH := $62  {Works with DOS 3.0 and higher}
  97.   end;
  98.   MsDos(regs);         {Get PSP address}
  99.   GetHandleTableAddr := Ptr(regs.BX, $18)
  100. end {GetHandleTableAddr};
  101.  
  102. {Causes "f" to become an "extended" file;  i.e.,  to remain  open  without using up any file handles.  The parameter "f" must be any  Turbo Pascal file;  e.g.,  a File, a File of Byte, a File of Foo,  Text,  etc.   This routine should be called immediately after the  Reset or Rewrite initially used to open "f." After "f" has become  extended,  it  cannot  be used by Turbo's built-in file  routines  until it has been unextended using UnExtend.}
  103.  
  104. procedure OpenExtend (var f);
  105. var
  106.   handle: Integer absolute f;
  107. begin
  108.   if not TablePtrOk then
  109.     begin
  110.       TablePtr := GetHandleTableAddr;
  111.       TablePtrOk := true
  112.     end;
  113.   SaveDcb := TablePtr^[handle];
  114.   TablePtr^[handle] := UnusedHandle;
  115.   handle := SaveDcb
  116. end {OpenExtend};
  117.  
  118. {Unextends  the extended file "f," so that it can be used by  any  of  Turbo Pascal's built-in file routines.   Note that  "f"  must  have  been  converted  to an extended file by  OpenExtend  before  invoking UnExtend(f).   After calling UnExtend, and then invoking  the  Turbo  Pascal file function on "f,"  ReExtend(f)  should  be  invoked  immediately  to re-extend "f" and restore the  DOS  file  state information.}
  119.  
  120. procedure UnExtend (var f);
  121. var
  122.   handle: Integer absolute f;
  123. begin
  124.   SaveDcb := TablePtr^[LastHandle];
  125.   TablePtr^[LastHandle] := Lo(handle);
  126.   handle := LastHandle
  127. end {UnExtend};
  128.  
  129.  
  130. {Re-extends  "f" into an extended file.   Note that "f" must have  been  converted  to  an extended file  by  OpenExtend,  and  then  unextended  using UnExtend,  before "f" can be re-extended  using  ReExtend.   ReExtend(f)  should be invoked immediately after  any  normal Turbo Pascal file function call using "f."}
  131.  
  132. procedure ReExtend (var f);
  133. var
  134.   handle: Integer absolute f;
  135. begin
  136.   handle := TablePtr^[LastHandle];
  137.   TablePtr^[LastHandle] := SaveDcb
  138. end {ReExtend};
  139.  
  140.  
  141.  
  142. TO USE THIS TECHNIQUE:
  143.  
  144. Make the above modifications.  Then --
  145.  
  146. At the top of your program, prior to the "program" statement, put 
  147. the  compiler  directive {$F252}.   (You may use a value  smaller 
  148. than 252,  if you wish.   Under DOS 2.0/2.1, values above 96 have 
  149. no additional benefit.   Each larger value for the {$F} directive 
  150. uses 2 additional bytes in the program's global data space.)  The  value you specify for the {$F} directive is the maximum number of  files  you  will be able to have open at the same  time  in  your  program.
  151.  
  152. Edit  your CONFIG.SYS file (see the DOS manual for  details),  so  that it includes a line that says "FILES=XXX".   XXX should be  a  number  that  is 3 greater than the value you specified  for  the  {$F} directive (larger values will provide no additional benefit,  with  respect to your individual program),  and should not exceed  99 (for DOS 2.0/2.1) or 255 (for DOS 3.0 and higher).   Under any  version of DOS,  the minimum allowable value for XXX is 8.  Then,  reboot your computer so that the FILES=XXX parameter takes  hold.   
  153.  
  154.  
  155.