home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST0811.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-31  |  3.1 KB  |  129 lines

  1. Unit InitOvly;
  2. { This unit will initialize the Overlay Manager.  It can be   }
  3. { used in the situation where some of the units that a        }
  4. { program uses have initialization code.  It is especially    }
  5. { useful when no source code is available to a unit, or you   }
  6. { cannot remove a unit's initialization code.                 }
  7. {$O-,F+}
  8. Interface
  9.  
  10. Uses OverLay;
  11.  
  12. Const
  13.   FileModeforOverlay = 0;  { Change this value for other mode }
  14.   OverlayFileName : String = ''; { Change to correct name     }
  15.  
  16. Implementation
  17.  
  18. Uses
  19.   Crt, Dos;
  20.  
  21. Var
  22.   OvrBufSize : LongInt;
  23. {$IFDEF VER55}
  24.   OldOvrReadFunc : OvrReadFunc;
  25. {$ENDIF VER55}
  26.  
  27. Function Exists( FName : String ) : Boolean;
  28. { This function returns either True or False, depending upon  }
  29. { whether the file FName was in the current directory.  It    }
  30. { uses a new way of determining the existance of the file.    }
  31. { It is no longer necessary to turn off I/O checking and then }
  32. { attempt to reset the file in order to determine if the file }
  33. { exists.                                                     }
  34.  
  35. Var
  36.   Result : String;      { Result of calling the FSearch Func  }
  37.  
  38. Begin
  39.   Result := FSearch( FName, '' );
  40.   Exists := Result <> '';
  41. End;
  42.  
  43. {$IFDEF VER55}
  44.  
  45. Procedure WriteMessageAt( X, Y : Byte; Message : String );
  46. { Output the message parameter at screen locations X and Y    }
  47.  
  48. Begin
  49.   GotoXY( X, Y );
  50.   Write( Message );
  51. End;
  52.  
  53.  
  54. Procedure HandleOvrErr( Error : Integer );
  55. { This procedure will handle any error that happens when the  }
  56. { program attempts to read from the .OVR file.  This way, we  }
  57. { have the capability to recover from the error.              }
  58. Var
  59.   ErrorString : String;
  60.  
  61. Begin
  62.   Str( Error, ErrorString );
  63.   WriteMessageAt( 10,10, ErrorString );
  64. End;
  65.  
  66. Function MyOvrRead( OvrSeg : Word ) : Integer;
  67. { This function will be called by the Overlay Manager before  }
  68. { any attempt is made to read from the file.  We must call    }
  69. { the original read function, which will return an error code }
  70. { to this function if it is not successful in reading the     }
  71. { required overlay from the .OVR file.                        }
  72. Var
  73.   Err : Integer;
  74.  
  75. Begin
  76.   Repeat
  77.     Err := OldOvrReadFunc( OvrSeg );
  78.     If( Err <> 0 ) Then
  79.       HandleOvrErr( Err );
  80.   Until Err = 0;
  81.   MyOvrRead := 0;
  82. End;
  83.  
  84. {$ENDIF}
  85.  
  86. Begin
  87. {$IFDEF VER55}
  88.  
  89.   OvrFileMode := FileModeforOverlay;
  90.  
  91. {$ENDIF}
  92.  
  93.   OvrInit( OverlayFileName );
  94.  
  95. {$IFDEF VER55}
  96.  
  97.   OldOvrReadFunc := OvrReadBuf;
  98.   OvrReadBuf := MyOvrRead;
  99.  
  100. {$ENDIF}
  101.  
  102.   While( OvrResult = OvrNotFound ) Do
  103.   Begin
  104.     Writeln( 'File not found: ', OverlayFileName, '.' );
  105.     Write( 'Enter new name: ' );
  106.     Readln( OverlayFileName );
  107.     OvrInit( OverlayFileName );
  108.   End;
  109.   If( OvrResult <> OvrOK ) Then
  110.   Begin
  111.     ClrScr;
  112.     Writeln( 'Unrecoverable Overlay Manager error.  Program Terminated.' );
  113.     Halt;
  114.   End;
  115.   OvrInitEMS;              { Will load the .OVR file into EMS }
  116.  
  117. {$IFDEF VER55}
  118.  
  119.   If( OvrResult = OvrOk ) Then
  120.   Begin
  121.     OldOvrReadFunc := OvrReadBuf;
  122.     OvrReadBuf := MyOvrRead;
  123.   End;
  124.   OvrSetRetry( OvrGetBuf Div 3 );
  125.  
  126. {$ENDIF}
  127.  
  128. End.
  129.