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

  1. Program TestFlushFileBuffers;
  2. { THis program will demonstrate the usage of the inline macro }
  3. { FlushFileBuffers.  This is used to guarantee that all info  }
  4. { has actually been written to the disk, and is not held in   }
  5. { memory.                                                     }
  6.  
  7. Type
  8.   Str4 = String[4];        { Componenet type for output file  }
  9.   FileType = File of Str4; { File type definition             }
  10.  
  11. Var
  12.   S : Str4;                { Variable to be written to file   }
  13.   F : FileType;            { Output file variable             }
  14.   I : Integer;             { Loop control variable            }
  15.   W : Word;                { Result of call to function       }
  16.  
  17. Function FlushFileBuffers( Var F ) : Word;
  18. { This inline macro will do several things on its way to      }
  19. { flush DOS's file buffers.  It first determines if the DOS   }
  20. { version is 3.3 or greater.  If so, it will make a call to   }
  21. { a special sub function of Int21 that will do the updating   }
  22. { for us.  Otherwise, it will force a duplicate of the file   }
  23. { handle.  It then goes on to close this duplicate handle.    }
  24. { If any errors are encountered by the routine, the error     }
  25. { value is returned in the AX register as the result type of  }
  26. { the function.                                               }
  27. Inline( $5F/            { POP DI }
  28.         $07/            { POP ES }
  29.         $B4/$30/        { MOV AH,30 }
  30.         $CD/$21/        { INT 21    }
  31.         $3C/$03/        { CMP AL,03 }
  32.         $7C/$18/        { JL  OTHER }
  33.         $80/$FC/$1E/    { CMP AH,1E }
  34.         $7D/$13/        { JGE  OTHER }
  35.         $B4/$45/        { MOV AH,45 }
  36.         $26/$8B/$1D/    { MOV BX,ES:[DI] }
  37.         $CD/$21/        { INT 21         }
  38.         $72/$14/        { JB  ERROR      }
  39.         $8B/$D8/        { MOV BX,AX      }
  40.         $B4/$3E/        { MOV AH,3E      }
  41.         $CD/$21/        { INT 21         }
  42.         $72/$0C/        { JB  ERROR      }
  43.         $EB/$07/        { JMP END        }
  44. { OTHER: }
  45.         $B4/$68/        { MOV AH,68      }
  46.         $26/$8B/$1D/    { MOV BX,ES:[DI] }
  47.         $CD/$21/        { INT 21         }
  48. { END:   }
  49.         $B8/$00/$00 );  { MOV AX,0       }
  50.  
  51. Begin
  52.   Assign( F, 'test514.dat' );  { Associate Name with file Var }
  53.   Rewrite( F );                { Open the file for Output     }
  54.   For I := 1 to 10 Do          { Place 10 values into file    }
  55.   Begin
  56.     Str( I, S );               { Convert counter to string    }
  57.     Write( F, S );             { Write counter to the file    }
  58.   End;                         {                              }
  59.   W := FlushFileBuffers( F );  { Call the function            }
  60.   Writeln( 'Call to FlushFileBuffers yields a ', W );
  61.                                { Echo results to the screen   }
  62.   Readln;                      { Pause for viewing of screen  }
  63. End.
  64.  
  65.