home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / STREAM15.ZIP / OVRDEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-03-27  |  1.6 KB  |  76 lines

  1. {$B-}   { Use fast boolean evaluation. }
  2.  
  3. program ovrdemo;
  4.  
  5. { Program to demonstrate use of two overlay files. }
  6.  
  7. {$i stdefine.inc}
  8.  
  9. {$ifndef overlays}
  10.    This program only works in modes that support overlays.
  11. {$endif}
  12.  
  13. uses
  14.   overlay,objects,streams,
  15.   ovr1,ovr2;
  16.  
  17. {$O ovr1}
  18. {$O ovr2}
  19.  
  20. type
  21.   PMessageStream = ^TMessageStream;
  22.   TMessageStream = object(TNamedBufStream)
  23.     { This stream prints its name every time anything is read from it. }
  24.  
  25.     procedure read(var buf; size:word); virtual;
  26.   end;
  27.  
  28. procedure TMessageStream.Read;
  29. begin
  30.   writeln('Reading from ',filename^);
  31.   TNamedBufStream.Read(buf,size);
  32. end;
  33.  
  34. var
  35.   stream1, stream2 : PMessageStream;
  36. begin
  37.   ovrinit('ovrdemo.ovr');
  38.  
  39.   writeln('The overlay streams aren''t being used yet.');
  40.  
  41.   proc1;
  42.   proc2;
  43.  
  44.   writeln('Now loading overlays to the two streams.');
  45.  
  46.   ovrclearbuf;    { Make sure no overlay is loaded. }
  47.  
  48.   new(stream1, init('ovrdemo.1',stCreate,2048));
  49.   ovrinitstream(stream1);
  50.  
  51.   proc1;          { This loads proc1 to Stream1, but doesn't trigger a read
  52.                     yet. }
  53.  
  54.   new(stream2, init('ovrdemo.2',stCreate,2048));
  55.   ovrinitstream(stream2);
  56.  
  57.   proc2;          { This loads proc2 to Stream2, but again, no read. }
  58.  
  59.   writeln('Now each unit is on a different stream; let''s call them a few ');
  60.   writeln('times.');
  61.  
  62.   proc1;
  63.   proc2;
  64.   proc1;
  65.   proc2;
  66.  
  67.   writeln('Now the overlay streams will be disposed of.');
  68.  
  69.   OvrDisposeStreams;
  70.  
  71.   writeln('These calls will use the old overlay mechanism.');
  72.   proc1;
  73.   proc2;
  74. end.
  75.  
  76.