[comp.lang.pascal] Various Turbo pascal questions

ppd491@leah.Albany.Edu (Peter P. Donohue) (11/23/89)

   I have a few questions pertaining to programming in Turbo Pascal 5.5
under the MS-Dos operating system. Any help with these would be
appreciated. 

  1) In an external data file (containing all ascii data), what is the
maximum length of a line allowed? 
  2) Is there a way to read any text that has been written to a screen?
I am writing a program that uses windows (that I write with pascal, not
the program) and I would like to be able to reset what was on the screen
after I clear a window.
  3) Is there a way to read the 'variables' (I'm not sure of the exact
name for them) that are set in AUTOEXEC.BAT with the SET command? An
example is with the program, Procomm, they let you set the path to the
program with the command 'SET PROCOMM=path'. Can you read what procomm
is set to with TP5.5 and how would you do it. 

   Thanks for any help and have a Happy Turkey Day!

						Pete  
-- 
Peter P. Donohue 
ppd491@albny1vx.bitnet               .  "Education is a journey,
ppd491@leah.albany.edu               .    not a destination..."

ts@uwasa.fi (Timo Salmi LASK) (11/24/89)

In article <2185@leah.Albany.Edu> ppd491@leah.Albany.Edu (Peter P. Donohue) writes:
>   I have a few questions pertaining to programming in Turbo Pascal 5.5

>  1) In an external data file (containing all ascii data), what is the
>maximum length of a line allowed? 

If you use ordinary strings the maximum is only 255 characters.
You can make it as long as 64K allows by adapting 
  var line : array [maxlengt] of char;
There are some good "LongString" routines in O'Brien, Turbo Pascal,
the Complete Reference.

>  2) Is there a way to read any text that has been written to a screen?
>I am writing a program that uses windows (that I write with pascal, not
>the program) and I would like to be able to reset what was on the screen
>after I clear a window.

Yes, you can do this using interrupts or by reading directly from
the video memory.  For more details see eg Ezzel, Programming the
IBM User Interface, or O'Brien, Turbo Pascal Advanced Programmer's
Guide. 

>  3) Is there a way to read the 'variables' (I'm not sure of the exact
>name for them) that are set in AUTOEXEC.BAT with the SET command? An
>example is with the program, Procomm, they let you set the path to the
>program with the command 'SET PROCOMM=path'. Can you read what procomm
>is set to with TP5.5 and how would you do it. 

You mean environment variables.  Please refer to your Tubo Pascal
manual and see the GetEnv function. 

...................................................................
Prof. Timo Salmi                                (Site 128.214.12.3)
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: ts@chyde.uwasa.fi Funet: vakk::salmi Bitnet: salmi@finfun

gaia@portia.Stanford.EDU (fai to leung) (11/24/89)

In article <2185@leah.Albany.Edu> ppd491@leah.Albany.Edu (Peter P. Donohue) writes:
>
>   I have a few questions pertaining to programming in Turbo Pascal 5.5
>under the MS-Dos operating system. Any help with these would be
>appreciated. 
>
>  1) In an external data file (containing all ascii data), what is the
>maximum length of a line allowed? 

I would say 255 characters long.
Pascal strings format are byte[0]=length of string follow by the ascii chars.
 
>  2) Is there a way to read any text that has been written to a screen?
>I am writing a program that uses windows (that I write with pascal, not
>the program) and I would like to be able to reset what was on the screen
>after I clear a window.

Character=mem[ScreenBase:(Y*NumberofColumnsOnScreen+X) shl 1];

X,Y starts from 0!!! i.e. wherex-1,wherey-1

ScreenBase of Monochrome $B000;
Others $B8000;
for some VGA & EGA textmodes $A000 (43,50 lines modes)

>  3) Is there a way to read the 'variables' (I'm not sure of the exact
>name for them) that are set in AUTOEXEC.BAT with the SET command? An
>example is with the program, Procomm, they let you set the path to the
>program with the command 'SET PROCOMM=path'. Can you read what procomm
>is set to with TP5.5 and how would you do it. 

YourData=getenv(YourSetStringInEnvironment{e.g. 'PROCOMM});

cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) (11/30/89)

Note:  I use TP4, so some changes they've made may render what I say incorrect
       or incomplete.

In article <2185@leah.Albany.Edu> ppd491@leah.Albany.Edu (Peter P. Donohue) writes:
$  1) In an external data file (containing all ascii data), what is the
$maximum length of a line allowed? 

   If you're reading it in one line at a time, I would think TP's limit of
255 characters would apply.  If you're reading it yourself and storing
it into some structure other than a string, you should be able to handle
as much data as you care to write your program to handle.

$  2) Is there a way to read any text that has been written to a screen?
$I am writing a program that uses windows (that I write with pascal, not
$the program) and I would like to be able to reset what was on the screen
$after I clear a window.

   The way I handle this is dependent on the machine having a standard
video card ... I have an array of integers absolute $b000:0000 and another
at $b800:0000.  When the program starts, I determine which one is the
screen memory in that machine, and then I use that one for direct screen
reads and writes.  It's worked on every card I've ever tried it on
(Herc/CGA/EGA/VGA), but I'm sure there are some machines out there
in the world that it wouldn't work on.

$  3) Is there a way to read the 'variables' (I'm not sure of the exact
$name for them) that are set in AUTOEXEC.BAT with the SET command? An
$example is with the program, Procomm, they let you set the path to the
$program with the command 'SET PROCOMM=path'. Can you read what procomm
$is set to with TP5.5 and how would you do it. 

   I don't know if TP has any built-in functions to handle this ... if
not, you have to check out the word at PSP:$2C.  This is the segment
address of the environment table.  Each entry in the table consists of
a bunch of characters, followed by a zero byte to end the string (standard
C format).  The end of the table is marked by an extra zero byte.
-- 
Stephen M. Dunn                               cs4g6ag@maccs.dcss.mcmaster.ca
          <std_disclaimer.h> = "\nI'm only an undergraduate!!!\n";
****************************************************************************
They say the best in life is free // but if you don't pay then you don't eat

eholmberg@kontu.utu.fi (11/30/89)

In article <257452CA.28297@maccs.dcss.mcmaster.ca>, cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) writes:
> In article <2185@leah.Albany.Edu> ppd491@leah.Albany.Edu (Peter P. Donohue) writes:
> $  3) Is there a way to read the 'variables' (I'm not sure of the exact
> 
>    I don't know if TP has any built-in functions to handle this ... if
> not, you have to check out the word at PSP:$2C.  This is the segment

Beginning from Turbo Pascal version 5.0, there is a way 
to read in environment variables: the function GetEnv. 
If you want to find out for example what's stored in 
the variable PROCOMM, simply call
   x := GetEnv('PROCOMM');
in your program, and x contains the variable. (GetEnv 
returns type String, so x must be String, too..).

Unfortunately, there seems to be no (clean) way to change 
the environment variables from a program.. :-(

+--------------------------------------------------------------------+
! E. K. Holmberg, eholmberg@kontu.utu.fi                  (Internet) !
!                 kontu::eholmberg                        (Decnet)   !
+--------------------------------------------------------------------+
! Also at SAS-(M)BBS (+358-21-518-994, 24h, V.32 ECM, 1200-9600 bps) !
+--------------------------------------------------------------------+