unit StreamFile;
interface
Uses
Classes, SysUtils;
Procedure AssignFile(
Var f: Textfile; Stream: TStream);
implementation
function FileNOPProc(
var t): Integer;
begin
Result := 0;
end;
function TextStreamIn(
var t: TTextRec): Integer;
Var
S: TStream;
Begin
t.BufEnd := 0;
t.BufPos := 0;
Move(t.UserData, S, SizeOf(TObject));
t.BufEnd := S.
Read(t.BufPtr^, t.BufSize);
Result := 0;
End;
Function TextStreamOut(
Var t: TTextRec): Integer;
Var
S: TStream;
Begin
Move(t.UserData, S, SizeOf(TObject));
If S.
Write(t.BufPtr^, t.BufPos) = t.BufPos
Then
Result := 0
Else
Result := 103;
t.BufPos := 0;
End;
Function TextStreamOpen(
Var t: TTextRec): Integer;
Var
Mode: Integer;
Begin
Mode := (fmInput
and 3);
Result := 0;
t.BufPos := 0;
t.BufEnd := 0;
t.FlushFunc := @FileNOPProc;
t.CloseFunc := @FileNOPProc;
If Mode = (t.Mode
and 3)
then
Begin
t.InOutFunc := @TextStreamIn;
End Else
Begin
t.InOutFunc := @TextStreamOut;
End;
End;
Procedure AssignFile(
Var f: Textfile; Stream: TStream);
Var
t: TTextRec
absolute f;
begin
FillChar(t, sizeof(TFileRec), 0);
t.BufPtr := @t.Buffer;
t.Mode := fmClosed;
t.Flags := tfCRLF * Byte(DefaultTextLineBreakStyle);
t.BufSize := sizeof(t.Buffer);
t.OpenFunc := @TextStreamOpen;
Move(Stream, t.UserData, SizeOf(TObject));
StrPCopy(t.
Name, '
Stream');
end;
end.