home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
PARADIS1
/
STRBUF.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-02-23
|
2KB
|
90 lines
(6900) Thu 20 Feb 92 4:57
By: Trevor Carlsen
To: Mike Hindle
Re: Re: Variable number of parameters
St:
---------------------------------------------------------------------------
@EID:5c87 18542727
@TCID:29f4ff54 5a1c
MH> Taking this one step further, I would like a routine capable
MH> of buffering output. Ie: a Write procedure allowing cursor
MH> positioning keeping the output in a buffer until a Writeln
MH> is used. Two benefits: Compact code and elimination of
MH> padding strings or using Spaces(# - Length(var)) or similar
This is simple to do using a text file device driver (TFDD). Here's a unit
that will do that. So if you want a formatted string just include this unit in
your uses declaration and -
OpenFStr(f); { f must be declared as type text }
write(f,'This will be formatted',r:8:2);
FormattedStr := GetFStr(f);
unit filestr;
{ Create a text file device driver to allow a formatted string }
interface
uses dos;
function GetFstr(var f: text): string;
procedure OpenFStr(var f: text);
{-----------------------------------------------------------------}
implementation
var
FStrBuff : string;
function GetFStr(var f: text): string;
begin
GetFStr := FStrBuff;
FStrBuff[0] := #0;
TextRec(f).BufPos := 0;
end; { GetFStr }
{$F+}
function FStrOpen(var f: TextRec):word;
{ This does nothing except return zero to indicate success }
begin
FStrOpen := 0;
end; { FStrOpen }
function FStrInOut(var f: TextRec):word;
begin
FStrBuff[0] := chr(F.BufPos);
FStrInOut := 0;
end; { FStrInOut }
{$F-}
procedure OpenFStr(var f: text);
begin
with TextRec(f) do begin
mode := fmClosed;
BufSize := Sizeof(buffer);
OpenFunc := @FStrOpen;
InOutFunc := @FStrInOut;
FlushFunc := @FStrInOut;
CloseFunc := @FStrOpen; { no need for special close function }
BufPos := 0;
BufEnd := 0;
BufPtr := @FStrBuff[1];
Name[0] := #0;
end; { with }
FStrBuff[0] := #0;
rewrite(f);
end; { OpenFStr }
end. { FileStr }
TeeCee
--- TC-ED v2.01
* Origin: The Pilbara's Pascal Centre (+61 91 732569) (3:690/644)
@PATH: 690/644 640/821 209/209 396/1 170/400 512/0 1007