home *** CD-ROM | disk | FTP | other *** search
- Unit TFDD;
- { This is the first sample Text File Device Driver. Its task }
- { is to send output from a Write or a Writeln statement into a }
- { string variable somewhere in memory. It will also introduce }
- { you to the structure of a Text File Device Driver, and what }
- { is necessary to implement one. }
- Interface
-
- Uses
- Dos;
-
- Type
- BufferType = String;
-
- Var
- theBuffer : BufferType;
- BufferPtr : Pointer;
-
- Procedure AssignDev( Var F : Text );
- { This procedure will set up the file variable F to point to }
- { each of the necessary support routines. It also will }
- { initialize each of the separate data fields within the text }
- { file variable that was passed to this routine. }
-
- Implementation
-
- {$F+} { Far Calls REQUIRED in a TFDD }
-
- Function NulRoutine( Var F : TextRec ) : Integer;
- { This routine will be assigned to any of the functions }
- { within the file routines that are not necessary. If will }
- { return a result of 0, which is reported for IOResult. This }
- { way any function that calls this is guaranteed to return }
- { with no errors. }
- Begin
- NulRoutine := 0; { Set function result to 0 = No Error }
- End;
-
- Function InOutRoutine( Var F : TextRec ) : Integer;
- { This is the routine that will handle the outputting of the }
- { information to the memory location used for the buffer. It }
- { is called anytime the program calls a Write or a Writeln }
- { statement. }
- Var
- I : Integer; { Loop counter used to write buffer }
-
- Begin
- With F Do
- Begin
- If Mode = fmOutput Then
- Begin
- If BufPos > BufEnd Then
- Begin
- For I := BufEnd To ( BufPos - 1 ) Do
- If( ( BufferType( BufferPtr^ )[0] ) < #255 )Then
- BufferType( BufferPtr^ ) :=
- BufferType( BufferPtr^ ) + BufPtr^[I];
- End;
- BufPos := BufEnd;
- InOutRoutine := 0;
- End
- Else
- InOutRoutine := 105;
- End;
- End;
-
- Procedure AssignDev( Var F : Text );
- { This procedure will set up the file variable F to point to }
- { each of the necessary support routines. It also will }
- { initialize each of the separate data fields within the text }
- { file variable that was passed to this routine. }
- Begin
- With TextRec( F ) Do
- Begin
- Handle := $FFFF;
- Mode := fmClosed;
- BufSize := SizeOf( Buffer );
- BufPtr := @Buffer;
- OpenFunc := @NulRoutine;
- FlushFunc := @NulRoutine;
- CloseFunc := @NulRoutine;
- InOutFunc := @InOutRoutine;
- Name[0] := #0;
- End;
- End;
-
- Begin
- BufferPtr := @theBuffer;
- FillChar( BufferPtr^, SizeOf( BufferPtr^ ), #0 );
- End.
-