Board index » delphi » Please help beginner!

Please help beginner!

I guess this is a pretty simple question but I've just started using
Pascal. Is there any way of directing the output to both the screen
AND a data file? I don't want to have to put 2 writeln's in (one to
write to the screen and one to write to a file).

If someone could reply ASAP I would be VERY grateful.

Thanks

Jawaz

 

Re:Please help beginner!


Quote
Jawaz Illavia (ja...@hkstar.com) wrote:

: I guess this is a pretty simple question but I've just started using
: Pascal. Is there any way of directing the output to both the screen
: AND a data file? I don't want to have to put 2 writeln's in (one to
: write to the screen and one to write to a file).

  Simultaneously?  Nope.  Not without a write for each file...

Bob
--
O.J. Verdict - The best innocence money can buy

Bob Gibson -- gib...@netcom.com

Re:Please help beginner!


Quote
Jawaz Illavia (ja...@hkstar.com) wrote:

: If someone could reply ASAP I would be VERY grateful.

As you already have figured out, you can use two writelns. Why not make a
PROCEDURE do that for you.

PROCEDURE WriteBoth(InStr : STRING);
 BEGIN
   WriteLn(InStr);            {Output on screen}
   WriteLn(YourFile, InStr);  {Output in file}  
 END;

Should works, haven't tried.

CU

  Martin

Mail me, if probz shows up :))

Re:Please help beginner!


Quote
In article <gibsonDHqnx4....@netcom.com> gib...@netcom.com "Bob Gibson" writes:
> Jawaz Illavia (ja...@hkstar.com) wrote:
> : I guess this is a pretty simple question but I've just started using
> : Pascal. Is there any way of directing the output to both the screen
> : AND a data file? I don't want to have to put 2 writeln's in (one to
> : write to the screen and one to write to a file).

>   Simultaneously?  Nope.  Not without a write for each file...

You can do it do writing a device driver!. The Abacus book, 'Turbo Pascal 6
System Programming' by Michael Tischer, has sample code for logging all screen
output to a text file.

          /----------------------------------------------------------\
          | Nigel Goodwin   | Internet : nig...@lpilsley.demon.co.uk |
          | Lower Pilsley   |                                        |
          | Chesterfield    |                                        |
          | England         |                                        |
          \----------------------------------------------------------/

Re:Please help beginner!


Quote
d.jae...@dl3bcq.dinoco.de (Detlev Jaeger) wrote:
>On 08.11.95, ja...@hkstar.com wrote:
>> Is there any way of directing the output to both the screen
>> AND a data file? I don't want to have to put 2 writeln's in (one to
>> write to the screen and one to write to a file).
>But unfortunately you have to put two wrriteln's in your source
>I think there's no other way
>Bye
>    Detlev
>--
>PGP public key available on key-servers and via receipt confirmation request

  You can do it by redirecting the output function of the text file:

type
  TOutputFunc = function (var F: TextRec): Integer;

var
  OldOutFunc: TOutputFunc;
  Redirect: Text;

OldOutFunc := TOutputFunc(TextRec(F).InOutFunc);
TextRec(F).InOutFunc := @MyOutFunc;

function MyOutFunc(var F: TextRec): Integer; far;
var
  Tmp: String;
begin
  Move(F.BufPtr^[B.BufPos], Tmp, F.BufEnd - F.BufPos);
  Tmp[0] := Chr(F.BufEnd - F.BufPos);
  Write(Redirect, Tmp);
  MyOutFunc := OldOutFunc(F);
end;

That's it. Out redefined output procedure first writes the contents of
the I/O buffer to the other file, and calls the original output
function.
I'm not sure in the way buffer is used. So this piece of code may be
wrong, but you can figure it yourself. (By looking at the variables:
BufPtr^, BufPos and BufEnd).

Hope this will be useful.

                                 Balazs Scheidler

----------------------------------------------------------------------
Bem Street 42.  | Learning informatics at the University of Veszprem
7100 Szekszard  | e-mail: ba...@vekoll.saturnus.vein.hu
Hungary         | Don't use that evil Wimpdoze, get Warped !  :-)
======================================================================
Microsoft Network is prohibited from redistributing this work  in any
form, in whole or in part without license. License to distribute this
work  is  available  to  Microsoft  at $500.  Transmission without
permission constitutes an agreement to these terms. Make money fast!
         I grant everyone the right to copy this signature.
----------------------------------------------------------------------

Re:Please help beginner!


Quote
In article <48kq08$...@hawk.pix.za>, bk000...@pixie.co.za (Brady Kelly) writes:
> ja...@hkstar.com (Jawaz Illavia) wrote:

>>I guess this is a pretty simple question but I've just started using
>>Pascal. Is there any way of directing the output to both the screen
>>AND a data file? I don't want to have to put 2 writeln's in (one to
>>write to the screen and one to write to a file).

> My advice only concerns Turbo Pascal. THe technique may be possible in
> standard Pascal, but that is beyond my knowledge.

> You can use a Text File Device Driver....

> Your subject includes the word beginner, and this is a fairly advanced
> task...

May I suggest something simpler?  I often find it handy to make my own
ouputting procedures.  In the simplest form, they look like this:

procedure Emit(S: string);
begin
   write(S);
end;

procedure EmitLn(S: string);
begin
   Emit(S + #13 +#10);
end;

This merely writes to the screen, and it looks clumsy, but oddly it saves
a little code space if you have many lines that emit.  But, the point of
it is that you can easily change where your output is going by changing
only the Emit procedure.  For your purpose, you'd use:

procedure Emit(S: string);
begin
   write(S);
   write(Fil,S);
end;

Fil, of course, must be an open text file variable.  You can write
complicated conditions for sending the data here or there and you can
use other ways to send data than the write procedure, but this'll get
you off to a start.

--
R. N. (dick) Wisan  - Email: internet WIS...@hartwick.edu
                    - Snail: 37 Clinton Street, Oneonta NY 13820, U.S.A.
                    - Just your opinion, please, ma'am: No fax.

Other Threads