home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / PNL002.ZIP / PNL002.TXT < prev    next >
Encoding:
Text File  |  1990-05-17  |  53.5 KB  |  2,179 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.                             
  15.                                                      
  16.                                                                  
  17.                                                                  
  18.                                 ////////    //    //    //   
  19.                                //    //    ///   //    //    
  20.                               //    //    ////  //    //     
  21.                              ////////    // // //    //      
  22.                             //          //  ////    //       
  23.                            //          //   ///    //          
  24.                           //          //    //    ///////    
  25.                                                                  
  26.                                                                  
  27.                                                              
  28.                                                             
  29.                                                             
  30.                                   Pascal NewsLetter         
  31.                                        Issue #2              
  32.                                       May, 1990             
  33.                                                             
  34.                                                             
  35.                                   Editor: Pete Davis         
  36.                                                             
  37.                                                             
  38.                                                             
  39.                                                             
  40.                                                             
  41.                                                             
  42.                                                             
  43.                                                             
  44.                                                             
  45.                                                             
  46.                                                             
  47.                                                             
  48.                                                                 
  49.                     The Programmer's Forum BBS is the home of
  50.                     PNL. It can be reached in Washington, DC at
  51.                     (202)966-3647. Information is available 
  52.                     through the following locations:        
  53.                                                             
  54.                     FidoNet: Pete Davis@1:109/138           
  55.                     GEnie: P.DAVIS5                          
  56.                     BitNet: HJ647C@GWUVM & UE356C@GWUVM
  57.                     InterNet:
  58.                     HJ647C@GWUVM.GWU.EDU & 
  59.                     UE356C@GWUVM.GWU.EDU
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.                                   Table of Contents
  79.  
  80.           Introduction ........................... Page 3  (Pete Davis)
  81.           Making the Point with Pointers ......... Page 5  (Pete Davis)
  82.           Neat Use of Object Files ............... Page 16 (Craig Thurber)
  83.           For Beginners .......................... Page 22 (Bob Gowans)
  84.           Conclusion ............................. Page 29 (Pete Davis)
  85.           Notice ................................. Page 32 (Pete Davis)
  86.           Distribution List ...................... Page 33 (Pete Davis)
  87.  
  88.  
  89.  
  90.  
  91.           Turbo Pascal is a registered trademark of Borland International
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                           2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.                                      Introduction
  145.  
  146.  
  147.  
  148.                Well,  school is over and it's time  for the second issue of
  149.  
  150.           PNL. I would first like to thank Robert  Garcia in Edinburgh (did
  151.  
  152.           I spell that  right?) Texas. He was the first person to give me a
  153.  
  154.           response. His praise alone would have  been enough for the second
  155.  
  156.           issue to  come out. He  also gave me  the idea for an  article on
  157.  
  158.           pointers for beginners.  I had  overlooked that, so  here it  is.
  159.  
  160.           Secondly, I  would like  to thank  Craig Thurber,  the author  of
  161.  
  162.           'Neat Use of Object Files' and Bob Gowans, the author of the 'For
  163.  
  164.           Beginners'  column.  I  really  liked  the articles  and  learned
  165.  
  166.           something new. Thanks Craig and Bob,  feel free to contribute any
  167.  
  168.           time. 
  169.  
  170.  
  171.  
  172.                I  would  like  to  point  out  that  I am  really  open  to
  173.  
  174.           submissions.  Please, if you write  an article, send  it to us. I
  175.  
  176.           can't guarantee when  or if it will  go in, but it  can't hurt to
  177.  
  178.           try. It takes some of the load off of my shoulders.
  179.  
  180.  
  181.  
  182.                One subject that I would really  like to see covered in PNL,
  183.  
  184.           is  Object Oriented  Programming  in Turbo  Pascal.  This is  one
  185.  
  186.           subject I will have to leave to others, at least for now, as I am
  187.  
  188.           not really  fluent in it yet. So, if  you're a hot-shot with OOP,
  189.  
  190.           please submit an article. It would be very beneficial to a lot of
  191.  
  192.           people, including me.
  193.  
  194.  
  195.  
  196.  
  197.                                                                           3
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.                I would really just  like to thank everyone that  I've heard
  213.  
  214.           from. Your compliments, suggestions, and  comments are what makes
  215.  
  216.           this worth doing. I hope to have the PNL going for as long as I'm
  217.  
  218.           computing.
  219.  
  220.  
  221.  
  222.                Oh yeah, and one last thing.  The release of PNL might be  a
  223.  
  224.           little sporadic. Maybe after a while I'll start setting some kind
  225.  
  226.           of time  period up, but right now, it's  whenever I get the time.
  227.  
  228.           I'm hoping to  be able to do  it more than once a  month, if time
  229.  
  230.           allows. I really do enjoy writing this.
  231.  
  232.  
  233.  
  234.                Well, until the next issue, thanks,  and please try to pitch
  235.  
  236.           in:  be it an  article, a suggestion,  or just passing  this file
  237.  
  238.           around to your local bulletin board. All of this helps.
  239.  
  240.  
  241.  
  242.                                                  _Pete Davis
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.                                                                           4
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.                             Making the Point with Pointers
  281.  
  282.  
  283.  
  284.                Those of you familiar  with C are probably very  comfortable
  285.  
  286.           with  pointers.  That's understandable,  you  can't program  in C
  287.  
  288.           without pointers (well, you can, but not well). Well, those of us
  289.  
  290.           that started on  Pascal have a little  more trouble understanding
  291.  
  292.           them. Part of the problem is that pointers seem almost foreign to
  293.  
  294.           the ideas and  methods of programming  in Pascal. In fact,  until
  295.  
  296.           getting involved in  more advanced  programming, one can  usually
  297.  
  298.           get away without  using pointers  at all. So,  why use  pointers?
  299.  
  300.           Well, there  are  several reasons.  For  one, and  probably  most
  301.  
  302.           important, it gives you access to the heap, all that extra memory
  303.  
  304.           you have in a 640K machine that  you normally can't use. In Turbo
  305.  
  306.           Pascal, you are  limited to  64k for any  single data  structure.
  307.  
  308.           This is a  pretty severe  limitation when you  are working  with,
  309.  
  310.           say, a database, or a word processor. Secondly, there are quite a
  311.  
  312.           few  structures that  are  more difficult  to  work with  without
  313.  
  314.           pointers, for example, a binary tree.
  315.  
  316.  
  317.  
  318.                There  are  a  multitude of  structures  that  pointers make
  319.  
  320.           possible.  Covering every  single  one of  them  would be  almost
  321.  
  322.           impossible. To make things a little more reasonable, I will cover
  323.  
  324.           the basic concept  of pointers, and then  the most common use  of
  325.  
  326.           them: The linked list. I will  leave coverage of other structures
  327.  
  328.           to  future  releases of  PNL. In  PNL001,  there was  an article:
  329.  
  330.           Generic Structures in Turbo Pascal, which covered a simple stack,
  331.  
  332.  
  333.                                                                           5
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.           using pointers. It  was a  more complicated version  of a  stack,
  349.  
  350.           actually, but the same ideas prevail for other structures. I will
  351.  
  352.           present a linked list with several operators. I will also include
  353.  
  354.           source code  to  the Linked  List  unit itself  and then  in  the
  355.  
  356.           article on  Sorting,  I will  include  some sorting  routines  to
  357.  
  358.           manipulate our linked list.
  359.  
  360.  
  361.  
  362.                Think of a  linked list as a  chain. Each link in  the chain
  363.  
  364.           contains some data.  At the end of that link is another link with
  365.  
  366.           more  data. You can add links to your chain and you can take them
  367.  
  368.           off. If  you take  a  link out  of the  middle, you  have to  re-
  369.  
  370.           connect your two chains to make a single chain. This is the basic
  371.  
  372.           premise for linked  lists. Depending  on how you  want your  data
  373.  
  374.           ordered (if you even want it ordered) decides how you insert your
  375.  
  376.           data. If you want a stack, you always add a link at the beginning
  377.  
  378.           of your chain. If you want a  queue, you always add a link at the
  379.  
  380.           end of  your chain. If  you want  a non-ordered linked  list, you
  381.  
  382.           could do either. If you want an ordered linked  list, though, you
  383.  
  384.           have to go through your list, find  out where your link goes, and
  385.  
  386.           insert it between  two other  links. (unless it's  the lowest  or
  387.  
  388.           highest value in the list)
  389.  
  390.  
  391.  
  392.                Below is a small diagram of a linked list. Following it is a
  393.  
  394.           short explanation.
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.                                                                           6
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.              Node 1               Node 2               Node 3
  417.           +----------+         +----------+         +----------+
  418.           |   Data   |    +--->|   Data   |    +--->|   Data   |
  419.           |  Item 1  |    |    |  Item 2  |    |    |  Item 3  |
  420.           +----------+    |    +----------+    |    +----------+
  421.           | Pointer  |----+    | Pointer  |----+    | Pointer  |-->NIL
  422.           +----------+         +----------+         +----------+
  423.  
  424.                Each node  in our  list contains  two things:  A Data  Item,
  425.  
  426.           which  the  programmer can  decide  on:  A record,  a  string, an
  427.  
  428.           integer,  etc.. Any  data  type will  do.  The second  item is  a
  429.  
  430.           pointer. The pointer points to the location in memory of the next
  431.  
  432.           node in the  list. The two nodes  don't have to be  anywhere near
  433.  
  434.           each other in memory, but as a programmer, they will appear to be
  435.  
  436.           right next to each-other. Notice the  NIL in the pointer in  Node
  437.  
  438.           3. This is  a reserved value  in pascal  that indicates that  the
  439.  
  440.           pointer is pointing to nothing. In our case, it signifies the end
  441.  
  442.           of the list. 
  443.  
  444.  
  445.  
  446.                Now, we are  missing one item in  our list, and that  is the
  447.  
  448.           pointer to the beginning of the  list. This is something that you
  449.  
  450.           must have, otherwise you won't know where in memory your list is.
  451.  
  452.           First, let's create our sample record and pointer:
  453.  
  454.  
  455.  
  456.  
  457.           type 
  458.             Samp_Ptr = ^Samp_Rec;      { A pointer to a Samp_Rec record }
  459.             Samp_Rec = record          { Our Samp_Rec record type       }
  460.                SampData : integer;     { Data can really be anything    }
  461.                Next_Rec : Samp_Ptr;    { Pointer to next item in list   }
  462.             end;
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.                                                                           7
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.                Ok, Samp_Ptr is a pointer to data of type Samp_Rec. You make
  485.  
  486.           a typed pointer by  including the '^'  before the data type  that
  487.  
  488.           you want to point to; in this case Samp_Rec. Notice that Samp_Ptr
  489.  
  490.           is declared before  Samp_Rec, yet Samp_Ptr  is a pointer to  type
  491.  
  492.           Samp_Rec. The reason for this is so that the Next_Rec pointer can
  493.  
  494.           be declared, making linked lists possible.
  495.  
  496.  
  497.  
  498.                Now, to help give us  something to work with, I'll  show the
  499.  
  500.           initialization  procedure, and then go into  a bit of explanation
  501.  
  502.           about how it works.
  503.  
  504.  
  505.           procedure Init_Samp_List(var Head : Samp_Ptr);
  506.  
  507.           { notice in our initialization that a record of type Samp_Rec is 
  508.            never defined nor used!                                       }
  509.            
  510.           begin
  511.             Head := nil;
  512.           end;
  513.  
  514.  
  515.                First  of all,  notice  that in  our  initialization we  are
  516.  
  517.           passing a pointer of type Samp_Ptr, and  not an actual record. It
  518.  
  519.           must also be passed as a variable parameter, as the variable Head
  520.  
  521.           will be given it's  initial value and that  value must return  to
  522.  
  523.           the  main program. The  only code in this  procedure is to assign
  524.  
  525.           the pascal reserved value of nil to Head. Head means the  head of
  526.  
  527.           the list, or the first link  in the list. nil is a  variable name
  528.  
  529.           supplied by pascal which  means that there is not  value assigned
  530.  
  531.           to the variable. In our case, it means that our list is empty.
  532.  
  533.  
  534.  
  535.  
  536.  
  537.                                                                           8
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.                Now, I want to supply a simple  insert procedure to insert a
  553.  
  554.           single value into the list. This will give us a little picture of
  555.  
  556.           how to manipulate our data with  pointers. The insert procedure I
  557.  
  558.           am providing here inserts a value into the beginning of the list.
  559.  
  560.           In the Turbo  Pascal Unit, enclosed,  you will find three  insert
  561.  
  562.           procedures: Insert_End, Insert_Begin,  and Insert_In_Order.  I'll
  563.  
  564.           leave Insert_Before, and Insert_After for you to write. They  way
  565.  
  566.           they are supposed  to work  is that Insert_Before  will insert  a
  567.  
  568.           record right in front of the  current record you are pointing to.
  569.  
  570.           To accomplish this, you need to pass  two items: The head, so you
  571.  
  572.           can go  through the  list again to  find out  what the  record is
  573.  
  574.           before  the current  record, and  the current record,  of course.
  575.  
  576.           Insert_After is a  little easier, in all that  needs to be passed
  577.  
  578.           is  the  current record.  The  record  you insert  should  end up
  579.  
  580.           pointing to the record  that was right after the  current record,
  581.  
  582.           and  the current  record should  end up pointing  to the  one you
  583.  
  584.           insert.  One  would rarely need  this many insert procedures,  in
  585.  
  586.           fact,  one  is  usually  enough.  So,  on  with our  Insert_Begin
  587.  
  588.           procedure:
  589.  
  590.  
  591.  
  592.           procedure Insert_Begin(var Head : Samp_Ptr; 
  593.                                Data_Value : integer);
  594.  
  595.           var
  596.             Temp : Samp_Ptr;  { A temporary variable to work with }
  597.  
  598.           begin
  599.             { Allocate memory for a Samp_Ptr }
  600.             new(Temp);                
  601.  
  602.  
  603.  
  604.  
  605.                                                                           9
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.             { Temp will become the first record and Head will become 
  621.               the second record in the list. But, we have to do things
  622.               kind of backwards, so first: Make head the second record }
  623.             Temp^.Next_Rec := Head;   
  624.  
  625.             { Now that Temp^.Next_Rec has a pointer to where the second
  626.               record is, we can now change the value of Head so that it
  627.               will be at the head of the list.                          }
  628.             Head:= Temp;
  629.  
  630.             { Next we need to put the value in this first record, that 
  631.               the user has provided to us.                              }
  632.             Head^.SampData := Data_Value;
  633.           end; {All done}
  634.  
  635.  
  636.                Here's what's going  on: First  of all, the  new command  is
  637.  
  638.           used to allocate  some space on  the heap for  our data. The  new
  639.  
  640.           procedure  returns  the  memory  location of  this  space  in the
  641.  
  642.           variable Temp. Instead of directly using a Samp_Rec data type, we
  643.  
  644.           use the  pointers  Temp and  Head  to access  the  fields in  our
  645.  
  646.           reserved space. To do this, the general construct is:
  647.  
  648.             POINTER^.FIELDNAME
  649.  
  650.  
  651.  
  652.                One can assign  something to this  place or receive a  value
  653.  
  654.           already stored. For example, to find the contents of SampData for
  655.  
  656.           the first record in the  list we could do the  following. (Assume
  657.  
  658.           that OurInt was previously defined as an integer.)
  659.  
  660.           OurInt := Head^.SampData;
  661.  
  662.           or we could change the contents by writing:
  663.  
  664.           Head^.SampData := OurInt;
  665.  
  666.  
  667.  
  668.                The most important step  and the one that seems to cause the
  669.  
  670.           most  problems  for  programmers  unfamiliar  with  pointers,  is
  671.  
  672.  
  673.                                                                          10
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.           maintaining and traversing the links in our list. Noticed what we
  689.  
  690.           did in  our Insert_Begin procedure - If we  are using a new list,
  691.  
  692.           then Head is going to have a value of nil :
  693.  
  694.  
  695.  
  696.           Head-> Nil
  697.  
  698.                First of all,  we allocate  some memory for  the record  and
  699.  
  700.           then assign the value of head to Temp^.Next_Rec :
  701.  
  702.  
  703.                   +----------+
  704.                   | SampData |
  705.           Temp -> | undefined|     
  706.                   +----------+     
  707.                   | Next_Rec |
  708.                   |   Nil    | 
  709.                   +----------+
  710.  
  711.  
  712.                Next we assigned Head to be equal to Temp:
  713.  
  714.  
  715.                   +----------+
  716.           Head -> | SampData |
  717.           Temp -> | undefined|     
  718.                   +----------+     
  719.                   | Next_Rec |
  720.                   |   Nil    | 
  721.                   +----------+
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.                After that, we had to assign the value to SampData. Suppose
  729.  
  730.           we passed the value of 4:
  731.  
  732.  
  733.                   +----------+
  734.           Head -> | SampData |
  735.           Temp -> |    4     |     
  736.                   +----------+     
  737.                   | Next_Rec |
  738.                   |   Nil    | 
  739.                   +----------+
  740.  
  741.                                                                          11
  742.  
  743.  
  744.  
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.                That  takes  care of  our first  value,  but what  about the
  757.  
  758.           second  value? How does  that work? Well,  if we follow  the same
  759.  
  760.           steps as before, let's  see where it leaves  us. Let's say  we're
  761.  
  762.           going to insert a value of 12 this  time. First of all we need to
  763.  
  764.           allocate space and Temp  will be pointing to that  space, then we
  765.  
  766.           assign Temp^.Next_Rec to Head:
  767.  
  768.  
  769.                   +----------+            +----------+
  770.                   | SampData |            | SampData |
  771.           Temp -> | undefined|    +-----> |    4     |
  772.                   +----------+    |       +----------+
  773.                   | Next_Rec |    |       | Next_Rec |
  774.                   |   Head   |----+       |   Nil    |
  775.                   +----------+            +----------+
  776.  
  777.  
  778.                Now, we assign the value of Head = Temp. That will move Head
  779.  
  780.           to the beginning of the list.
  781.  
  782.  
  783.                   +----------+            +----------+
  784.           Head -> | SampData |            | SampData |
  785.           Temp -> | undefined|    +-----> |    4     |
  786.                   +----------+    |       +----------+
  787.                   | Next_Rec |    |       | Next_Rec |
  788.                   |   -------|----+       |   Nil    |
  789.                   +----------+            +----------+
  790.  
  791.  
  792.                Now we assign the value of Data_Value (12) to the SampData
  793.  
  794.           field.
  795.  
  796.  
  797.  
  798.                   +----------+            +----------+
  799.           Head -> | SampData |            | SampData |
  800.           Temp -> |    12    |    +-----> |    4     |
  801.                   +----------+    |       +----------+
  802.                   | Next_Rec |    |       | Next_Rec |
  803.                   |   -------|----+       |   Nil    |
  804.                   +----------+            +----------+
  805.  
  806.  
  807.  
  808.  
  809.                                                                          12
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.                That just about  does it  for the insert  procedure. It's  a
  825.  
  826.           very difficult concept for beginners to understand and that's why
  827.  
  828.           I am supplying all of the diagrams. I want to make the concept of
  829.  
  830.           pointers themselves as clear as possible. Once you understand the
  831.  
  832.           concept, the different operations on them become easy. If at this
  833.  
  834.           point you still don't understand, I  suggest that you reread from
  835.  
  836.           the top of the article and give it another try.  If at that point
  837.  
  838.           you still don't understand, try putting it away for a day  or two
  839.  
  840.           and try again. I find that putting a difficult concept away for a
  841.  
  842.           little while and coming back to it makes it easier to understand.
  843.  
  844.  
  845.  
  846.                Like the insert  operations, the  delete operations come  in
  847.  
  848.           all  shapes  and  sizes.  The   accompanying  unit  contains  the
  849.  
  850.           following: Pop_First  (for stack  use),  Pop_Last(for queue)  and
  851.  
  852.           Delete_Here. Again, I will  leave Delete_Before and  Delete_After
  853.  
  854.           for you to write.  With the three I provide, it  should be fairly
  855.  
  856.           simple. These are more  than enough for the typical  linked list.
  857.  
  858.           The main problem with doing the  delete is that you have to  find
  859.  
  860.           out where you are in the list before you can take any action.  If
  861.  
  862.           you want to delete the first node  in the list, then you have  to
  863.  
  864.           re-assign the Head of the list to the second item in the list. If
  865.  
  866.           you want to delete  something from the end of the  list, you need
  867.  
  868.           to  make sure that the  Next_Rec field is set to  Nil in the last
  869.  
  870.           record. If you want to delete something in the middle of the list
  871.  
  872.           then you have to  reconnect to second half of the  list to what's
  873.  
  874.           left of the first half.
  875.  
  876.  
  877.                                                                          13
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.           Using our first diagram:
  893.  
  894.  
  895.              Node 1               Node 2               Node 3
  896.           +----------+         +----------+         +----------+
  897.           |   Data   |    +--->|   Data   |    +--->|   Data   |
  898.           |  Item 1  |    |    |  Item 2  |    |    |  Item 3  |
  899.           +----------+    |    +----------+    |    +----------+
  900.           | Pointer  |----+    | Pointer  |----+    | Pointer  |-->NIL
  901.           +----------+         +----------+         +----------+
  902.  
  903.                If we take out Node 2, we have to assign the pointer in Node
  904.  
  905.           1 to point to  Node 3. If we get  rid of Node 3, we need  to have
  906.  
  907.           the Pointer in Node 2 be nil. 
  908.  
  909.              Node 1               Node 2               Node 3
  910.           +----------+         +----------+         +----------+
  911.           |   Data   |    X--->|   Data   |    X--->|   Data   |
  912.           |  Item 1  |    X    |  Item 2  |    X +->|  Item 3  |
  913.           +----------+    X    +----------+    X |  +----------+
  914.           | Pointer  |--+-X    | Pointer  |----X |  | Pointer  |-->NIL
  915.           +----------+  |      +----------+      |  +----------+
  916.                         +------------------------+
  917.  
  918.                This brings up the  need for one more procedure  provided in
  919.  
  920.           pascal, and that's  the dispose procedure. The  dispose procedure
  921.  
  922.           returns whatever space  you have  allocated back to  the heap  so
  923.  
  924.           that it can be  reused. You don't always have to  do that, but if
  925.  
  926.           you are  working with  a lot  of data  and you get  rid of  links
  927.  
  928.           without using the dispose  procedure, you are more likely  to run
  929.  
  930.           out of heap memory. I will let you look at the source code for an
  931.  
  932.           example of the dispose procedure.
  933.  
  934.  
  935.  
  936.                I'm going to  have to keep  myself from including more  code
  937.  
  938.           examples in the  magazine, and instead let you  see the unit that
  939.  
  940.           is included with this issue. It  has all the necessary procedures
  941.  
  942.           and  functions, and then  some. Each one has  a description as to
  943.  
  944.  
  945.                                                                          14
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.           it's  function. I don't feel  that further explanation here would
  961.  
  962.           be beneficial. In  other words, I'm out of  breath and thought. I
  963.  
  964.           don't know what else I could tell you.
  965.  
  966.  
  967.  
  968.                I hope this  article has been  helpful, and if anyone  feels
  969.  
  970.           that I've missed something important, I'll do a follow-up article
  971.  
  972.           on it. I will be showing other  uses of pointers in other issues,
  973.  
  974.           but it is unlikely that I will keep it this basic,  unless demand
  975.  
  976.           keeps things at this level.
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.                                                                          15
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.                                NEAT USE OF OBJECT FILES
  1029.  
  1030.                                   by Craig Thurber 
  1031.  
  1032.            
  1033.  
  1034.                Not  long ago I  wanted to do  something simple:   include a
  1035.  
  1036.           downloadable soft font file in a compiled Pascal .EXE file.  This
  1037.  
  1038.           seemed like  an easy  thing to  do, but  alas, I  could not  find
  1039.  
  1040.           anything in  my documentation  or  reference books  that gave  an
  1041.  
  1042.           indication of how  to do it.   It wasn't long before  some of the
  1043.  
  1044.           fine users of this language pitched  in and provided an answer to
  1045.  
  1046.           the  problem.  The answer  has proven to be a  neat use of object
  1047.  
  1048.           files.  The inclusion of text or other types of files in the .EXE
  1049.  
  1050.           forms has a  number of advantages, the most notable of which is a
  1051.  
  1052.           very quick  access to  what might  otherwise be  a separate  disk
  1053.  
  1054.           file.  Since the  equivalent of the disk  file is already  loaded
  1055.  
  1056.           into memory, there is no need to wait for a floppy disk file to 
  1057.  
  1058.           be accessed. 
  1059.  
  1060.            
  1061.  
  1062.                The  method and  some  examples are  presented below.   Many
  1063.  
  1064.           thanks to Juan  Jimenez for both  his insights into this  problem
  1065.  
  1066.           and his  patients in providing an answer for  which I had no more
  1067.  
  1068.           questions.  Juan answered the message that I posted in  the GEnie
  1069.  
  1070.           Borland  Roundtable.    If you  are  interested  in  a very  fine
  1071.  
  1072.           service, please consider this one*. 
  1073.  
  1074.  
  1075.  
  1076.           External Procedure Calls 
  1077.           ------------------------ 
  1078.  
  1079.                External procedures can be declared and called in the Pascal
  1080.  
  1081.                                                                          16
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.           language.   The  user manual  suggests that  this  capability was
  1097.  
  1098.           included  in  the language  primarily  for inclusion  of assembly
  1099.  
  1100.           language routines in  the compiled  versions of Pascal  programs.
  1101.  
  1102.           However, the call to an external procedure can also be used to 
  1103.  
  1104.           move  the contents  of a  text  or other  type file  to  a Pascal
  1105.  
  1106.           pointer location, and then to  perform standard Pascal operations
  1107.  
  1108.           with the data that resides at that pointer location.  Declaration
  1109.  
  1110.           of  an  external  procedure  call  is  made  with  the  following
  1111.  
  1112.           statement in a Pascal program or unit: 
  1113.  
  1114.  
  1115.  
  1116.           procedure HelloJuan;  external;  {$L HELLO.OBJ} 
  1117.  
  1118.            
  1119.  
  1120.           In the above example, the external file named HELLO.OBJ will be 
  1121.  
  1122.           included in the compilation  of the .EXE file.  The {$L} compiler
  1123.  
  1124.           directive is the  local symbol information directive.   Note that
  1125.  
  1126.           this  compiler  directive  is ignored  if  the  Debug Information
  1127.  
  1128.           setting {$D-} is set to off. 
  1129.  
  1130.            The  overall effect  of  this declaration  is that  the external
  1131.  
  1132.           object file  named HELLO.OBJ is recorded in the .TPU or .EXE file
  1133.  
  1134.           at the time of compilation.  While this inclusion will increase 
  1135.  
  1136.           the size of these files, it does not slow program execution. 
  1137.  
  1138.  
  1139.  
  1140.            Creation of Object Files 
  1141.           ------------------------ 
  1142.  
  1143.           Object files  are  created with  the BINOBJ.EXE  utility that  is
  1144.  
  1145.           provided with  Turbo Pascal.  The procedure involves invoking the
  1146.  
  1147.           BINOBJ.EXE procedures with a designated file for conversion and 
  1148.  
  1149.                                                                          17
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.           an external name to give to the file.  In the case shown above, 
  1165.  
  1166.           the test file  HELLO.TXT would  be converted to  the object  file
  1167.  
  1168.           HELLO.OBJ having the  external procedure call HelloJuan  with the
  1169.  
  1170.           following command (assuming the given drives and directories):  
  1171.  
  1172.             C:\TP\BINOBJ A:\HELLO.TXT A:\HELLO.OBJ HELLOJUAN 
  1173.  
  1174.            
  1175.  
  1176.           When creating object files, keep track of the original file size.
  1177.  
  1178.           You  will need  it  later  when  you  invoke  them  in  a  Pascal
  1179.  
  1180.           procedure. 
  1181.  
  1182.            
  1183.  
  1184.           Using the External Procedure 
  1185.           ---------------------------- 
  1186.  
  1187.                Suppose that you  started by  declaring the above  procedure
  1188.  
  1189.           after converting the file HELLO.TXT to the object file HELLO.OBJ.
  1190.  
  1191.           The original text  file contained  the statement "Hello,  Juan.",
  1192.  
  1193.           which is 13 characters long.  After conversion to an object file,
  1194.  
  1195.           be  sure not to confuse the byte size of the object file with the
  1196.  
  1197.           size  of the original text file;  it  is the size of the original
  1198.  
  1199.           file that you  will need while  writing the Pascal code.  Suppose
  1200.  
  1201.           also  that  the objective  of  your  programming is  to  send the
  1202.  
  1203.           statement  "Hello,  Juan." from  the  compiled .EXE  file  to the
  1204.  
  1205.           printer.   Here is  the code  that will  do this,  as a  complete
  1206.  
  1207.           program.  Each statement in the program is explained below.  
  1208.  
  1209.  
  1210.             program Hello; 
  1211.            
  1212.               uses Printer; 
  1213.            
  1214.               procedure HelloJuan;  external;  {$L+ HELLO.OBJ} 
  1215.            
  1216.  
  1217.                                                                          18
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.                 var PtrStr    : Pointer; 
  1233.                     OutString : String; 
  1234.            
  1235.                 begin 
  1236.                   PtsStr := @HelloJuan; 
  1237.                   Move(PtrStr^,OutStr[1],13); 
  1238.                   OutStr[0] := Chr(11); 
  1239.                   Writeln(Lst,OutStr) 
  1240.                 end. 
  1241.            
  1242.  
  1243.  
  1244.  
  1245.           The  result  of running  this  file  will be  printing  the words
  1246.  
  1247.           "Hello, Juan" on the printer that is located at LPT1. 
  1248.  
  1249.            
  1250.  
  1251.                As nice  a fellow as  Juan is, I  don't suppose that  making
  1252.  
  1253.           your printer say hello to him is very useful to you.   So here is
  1254.  
  1255.           another  example.   Suppose  you want  a full  screen of  text to
  1256.  
  1257.           appear instantly.   You have written programs that make a call to
  1258.  
  1259.           an external file and have watched them slowly write one line at a
  1260.  
  1261.           time  down the screen;  you have  had enough of this and you want
  1262.  
  1263.           the speed that  Pascal normally shows.   Well, this could  be the
  1264.  
  1265.           answer.  Write your text file, note the length of it (I'll use 
  1266.  
  1267.           2000 here) and then change the above program as shown below.  For
  1268.  
  1269.           purposes of this article,  I have assumed that the file names and
  1270.  
  1271.           external declarations are the same;   the only difference is that
  1272.  
  1273.           you are  now writing  a nice letter  to Juan  and you want  it to
  1274.  
  1275.           appear on  the screen very quickly.   Here is the  procedure code
  1276.  
  1277.           that will do it: 
  1278.  
  1279.            
  1280.             procedure HelloJuan;  external;  {$L HELLO.OBJ} 
  1281.                 
  1282.               const Size = 2000; 
  1283.            
  1284.  
  1285.                                                                          19
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.               var PtrStr : Pointer; 
  1301.                   OutStr : Array[1..2000] of Char; 
  1302.                   Index  : Integer; 
  1303.            
  1304.               begin 
  1305.                 PtrStr := @HelloJuan; 
  1306.                 Move(PtrStr^,OutStr[1],Size); 
  1307.                 For Index := 1 to Size do 
  1308.                   Write(OutStr[Index]) 
  1309.               end; 
  1310.            
  1311.  
  1312.  
  1313.           What's That Code All About? 
  1314.           --------------------------- 
  1315.  
  1316.           Here is what the coding is all about: 
  1317.  
  1318.            
  1319.  
  1320.                Variable declarations:  PtrStr is a  generic pointer.  It is
  1321.  
  1322.           used to mark the starting location of the compiled external file.
  1323.  
  1324.           OutStr is an array  that is large enough to hold  the contents of
  1325.  
  1326.           the externally  declared procedure.   Index is  a simple  counter
  1327.  
  1328.           that is  used  to track  the  feeding of  each character  of  the
  1329.  
  1330.           compiled external file to the screen. 
  1331.  
  1332.            
  1333.  
  1334.                PtrStr := @HelloJuan; :  This statement moves the pointer to
  1335.  
  1336.  
  1337.  
  1338.           The start of  the procedure that  was named HelloJuan during  the
  1339.  
  1340.           conversion of the text file to an object file. 
  1341.  
  1342.  
  1343.  
  1344.                Move(PtrStr^,OutStr[1],Size);:    This  statement moves  the
  1345.  
  1346.           number  of bytes  specified by  Size from  the starting  location
  1347.  
  1348.           specified by PtrStr^ to the first element of the array OutStr.  
  1349.  
  1350.            
  1351.  
  1352.  
  1353.                                                                          20
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.                For Index ... do  : This loop dumps the array  OutStr to the
  1369.  
  1370.           screen  one element at  a time.   The resulting screen  dump will
  1371.  
  1372.           appear exactly as the original text file was written.   
  1373.  
  1374.            
  1375.  
  1376.           What Else Does It Do? 
  1377.           --------------------- 
  1378.  
  1379.                The  conversion of files  to object  files and  inclusion of
  1380.  
  1381.           them in the executable form of a program offers a wide variety of
  1382.  
  1383.           opportunities for programmers.   In principle, any file  that you
  1384.  
  1385.           can present  on  the screen  or printer  can be  converted to  an
  1386.  
  1387.           object  file   and  then  included   in  the  .EXE   file  during
  1388.  
  1389.           compilation.   When  the  procedure  is  called using  the  above
  1390.  
  1391.           techniques,  the results will be very  quick and will be an exact
  1392.  
  1393.           duplicate of what you would get by  other means.  So if you  want
  1394.  
  1395.           to have  a fast way  of accessing  help files, graphics  or other
  1396.  
  1397.           files, give the method a try.  
  1398.  
  1399.            
  1400.  
  1401.           * A GEnie account can be obtained by calling 1-800-638-9636.
  1402.  
  1403.  
  1404.  
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410.  
  1411.  
  1412.  
  1413.  
  1414.  
  1415.  
  1416.  
  1417.  
  1418.  
  1419.  
  1420.  
  1421.                                                                          21
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.                                     For Beginners
  1437.  
  1438.                                     By Bob Gowans
  1439.  
  1440.             
  1441.  
  1442.                Where to start? A  good question - the beginner's  column is
  1443.  
  1444.           aimed  at  people with  little or  no   programing  experience of
  1445.  
  1446.           Pascal  and  will start at  a very basic  level but will graduate
  1447.  
  1448.           (hopefully) to  more  complicated  programming  routines  as  our
  1449.  
  1450.           confidence in  the use of Pascal increases. With  this in  mind I
  1451.  
  1452.           would  appreciate  any  feedback on  my  articles  - suggestions,
  1453.  
  1454.           constructive criticism and especially  any neat programing tricks
  1455.  
  1456.           that beginners would find useful. I will give details on  contact
  1457.  
  1458.           addresses at the end of this article.   
  1459.  
  1460.  
  1461.  
  1462.                Pascal  has  to be  taught  in  a way  that  encourages good
  1463.  
  1464.           programing. As  a high-level  language it  is structured  in this
  1465.  
  1466.           way and can allow the Pascal programer to present his programs in
  1467.  
  1468.           a  manner  of  clarity  that  is  almost  unparalleled  by  other
  1469.  
  1470.           high-level  languages. So  if  you have  just  bought the  latest
  1471.  
  1472.           version of  your favorite  Pascal compiler  and your fingers  are
  1473.  
  1474.           itching to  get at the keyboard  to write that ultra  program you
  1475.  
  1476.           have always  wanted to  produce to  impress  your friends,  wife,
  1477.  
  1478.           boss?  Then  stop!  Good  programs  take  a lot  of  thought  and
  1479.  
  1480.           planning before you  reach the actual  coding stage. In fact,  an
  1481.  
  1482.           English  language  equivalent  of your  program  should  first be
  1483.  
  1484.           produced, showing  step by step what your  program does. Moreover
  1485.  
  1486.           this English language  version should be  able to make clear,  to
  1487.  
  1488.  
  1489.                                                                          22
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.           non-programers, exactly what  your program is  going to do.  This
  1505.  
  1506.           may not be essential  for the relatively small programs  which we
  1507.  
  1508.           will encounter at  this stage but  it is an invaluable  technique
  1509.  
  1510.           when  writing  large  programs  (such  as  the  impressive  ultra
  1511.  
  1512.           program) and   as  an aid to  problem solving.  It is  well worth
  1513.  
  1514.           while  getting  into the  habit  of  using this  method  known as
  1515.  
  1516.           TOP-DOWN design to  plan you programs.  In future articles it  is
  1517.  
  1518.           hoped that  I will be able to introduce this method but meanwhile
  1519.  
  1520.           lets  get back  to those  itching fingers  and get  on with  some
  1521.  
  1522.           program   writing. The  programs given  as examples are  standard
  1523.  
  1524.           Pascal,  that is they  should compile using  any Pascal compiler,
  1525.  
  1526.           however I have only used Turbo Pascal V4 to try them out and test
  1527.  
  1528.           them. Here is a simple but complete Pascal program: 
  1529.  
  1530.             
  1531.           program hello_there;   { This is our first program } 
  1532.           begin 
  1533.              write('Hello'); 
  1534.              writeln(' my name is Bob'); 
  1535.              write('How are you?') 
  1536.           end. 
  1537.             
  1538.  
  1539.                Lets break  this program  down to it's  component parts  and
  1540.  
  1541.           examine  each  part in  turn. The  program  starts with  the word
  1542.  
  1543.           program followed by a space followed by the program name. In this
  1544.  
  1545.           case  the name is hello_there but subject to some rules, it could
  1546.  
  1547.           be anything we chose,  however it is good programing  practice to
  1548.  
  1549.           chose a  name that is  relevant to  what the  program does.  Such
  1550.  
  1551.           names are given the term IDENTIFIERS. 
  1552.  
  1553.           Rules for identifiers: 
  1554.  
  1555.  
  1556.  
  1557.                                                                          23
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.           1) An identifier must begin with a letter. 
  1573.  
  1574.  
  1575.  
  1576.           2)  They  may  then  consist  of  letters and  digits,  upper  or
  1577.  
  1578.           lowercase letters are treated as identical. 
  1579.  
  1580.  
  1581.  
  1582.           3) They  can contain  embedded underscore  characters to  improve
  1583.  
  1584.           readability as has been done in  our example program identifier -
  1585.  
  1586.           hello_there. 
  1587.  
  1588.  
  1589.  
  1590.           4) They can be of any length but generally speaking  the compiler
  1591.  
  1592.           will ignore anything following the first 8 identifier characters.
  1593.  
  1594.  
  1595.  
  1596.           Examples of Identifiers:   
  1597.  
  1598.           accounts     A386XT     Income_Tax     BUDGET1990 
  1599.  
  1600.             
  1601.  
  1602.           Try  this  self-test,  the answers   are  given  at  the  end  of
  1603.  
  1604.           the  article. 
  1605.  
  1606.             
  1607.  
  1608.           Which of the following are valid identifiers: 
  1609.  
  1610.           a) FirstRun 
  1611.  
  1612.           b) Mississippi 
  1613.  
  1614.           c) Locust12 
  1615.  
  1616.           d) George Washington 
  1617.  
  1618.           e) Program 
  1619.  
  1620.           f) 123go 
  1621.  
  1622.           g) accounts.1990 
  1623.  
  1624.  
  1625.                                                                          24
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.                By the way,  reserved words, that  is words that the  Pascal
  1641.  
  1642.           language  itself uses, cannot  be used as  valid identifiers. The
  1643.  
  1644.           complete list of  Pascal reserved words  should be found in  your
  1645.  
  1646.           manual or any decent book on Pascal. 
  1647.  
  1648.             
  1649.  
  1650.                Going  back  to our  program,  the program  heading (Program
  1651.  
  1652.           hello_there;)  has  a semi-colon  at  the  end of  the  line. The
  1653.  
  1654.           program heading  does not contain  any actual commands  it simply
  1655.  
  1656.           marks the beginning of the program. Program commands come between
  1657.  
  1658.           the Pascal reserved words begin and end, they are often referred
  1659.  
  1660.           to as the  statements part of the program and each statement line
  1661.  
  1662.           is separated  by a  semi-colon(;). The  statements part   of  the
  1663.  
  1664.           program contains a  series of  instructions for  the computer  to
  1665.  
  1666.           execute.   Our example  program contains  statements designed  to
  1667.  
  1668.           write output to the screen. To write  a line of output 
  1669.  
  1670.           the   standard   output   procedure    writeln,   the   form   is
  1671.  
  1672.           writeln('textout'). 
  1673.  
  1674.  
  1675.  
  1676.                Writeln  and write  are very  similar  in what  they  do but
  1677.  
  1678.           writeln has  the advantage  of performing  a carriage  return  so
  1679.  
  1680.           your  next writeln   statement would  write out  text   on a  new
  1681.  
  1682.           line. Try   the  program   and   make sure    you understand  the
  1683.  
  1684.           differences between write  and writeln. Note that  each statement
  1685.  
  1686.           in the  statements part is separated by a semi-colon 
  1687.  
  1688.           except the  one preceding   the  reserved word  end and that  the
  1689.  
  1690.           final end in the program is followed by a period. Finally  on the
  1691.  
  1692.  
  1693.                                                                          25
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.           program  heading  line you  will  have  noticed that  there  is a
  1709.  
  1710.           comment  in curly brackets.  You can place  comments at strategic
  1711.  
  1712.           points in your  program to  add clarity. Comments  will help  you
  1713.  
  1714.           when you want   to amend you programs   after you have   not used
  1715.  
  1716.           them for  some  time they will  show what  your intention was  at
  1717.  
  1718.           the  time   you  wrote   the  program, something  you  may   have
  1719.  
  1720.           forgotten as time  goes by. The  rule is  you can place  comments
  1721.  
  1722.           at relevant points   in the program  as long as   they are placed
  1723.  
  1724.           within curly brackets.  Here are  some more examples  for you  to
  1725.  
  1726.           try: 
  1727.  
  1728.             
  1729.           program  Name_and_address;
  1730.           {  writes to  the screen  your name  and address  } 
  1731.           begin 
  1732.              writeln('My Initials Surname'); 
  1733.              writeln('Department of Computer Science'); 
  1734.              writeln('  The  University');
  1735.             {  note  the use  of  spaces  for  output  } 
  1736.              writeln('        City'); 
  1737.              writeln('         Country') 
  1738.           end. 
  1739.             
  1740.  
  1741.           Writeln is  handy for  inserting blank  lines so  that your  text
  1742.  
  1743.           output looks better 
  1744.  
  1745.           program nice_lines; 
  1746.           begin 
  1747.              writeln('Line one'); 
  1748.              writeln; { inserts a blank line } 
  1749.              writeln('Line three') 
  1750.           end. 
  1751.             
  1752.  
  1753.                Just  to get  you thinking,  write  a Pascal  program that 
  1754.  
  1755.           would produce  the following output to the screen: 
  1756.  
  1757.             
  1758.  
  1759.           'How many times have I told you, don't do that'; she said. 
  1760.  
  1761.                                                                          26
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.             
  1777.  
  1778.           Clue - watch the quotation marks!   
  1779.  
  1780.  
  1781.  
  1782.           TIP - If you are using Turbo Pascal  there is a neat routine
  1783.  
  1784.           provided to clear the screen. It can be implemented as follows: 
  1785.  
  1786.             
  1787.           program clear; 
  1788.           uses crt; { this must be here and is for turbo pascal only } 
  1789.           begin 
  1790.              clrscr;  { turbo pascal clear screen routine } 
  1791.              ........... 
  1792.              ........... 
  1793.           end. 
  1794.             
  1795.  
  1796.                I hope you have found this article helpful in the next issue
  1797.  
  1798.           I hope  to discuss  variable types  found in  Pascal, more  about
  1799.  
  1800.           top-down design  and provide  more tips.  I will  also provide  a
  1801.  
  1802.           solution to the exercise. In case you cannot wait and are pulling
  1803.  
  1804.           your hair out in frustration you can contact  me at the following
  1805.  
  1806.           Email addresses for the solution. I would also be pleased to help
  1807.  
  1808.           beginners with Pascal programing problems as well. 
  1809.  
  1810.             
  1811.  
  1812.           JANET - MCGDRKG@UK.AC.MCC.CMS 
  1813.  
  1814.           INTERNET - MCGDRKG%MCC.CMS.AC.UK@CUNYVM.CUNY.EDU 
  1815.  
  1816.           EARN/BITNET - MCGDRKG%MCC.CMS.AC.UK@UKACRL 
  1817.  
  1818.             
  1819.  
  1820.           I would  really appreciate  useful routines  for publication  and
  1821.  
  1822.           especially nice little  tricks like the clear-screen  routine for
  1823.  
  1824.           turbo pascal which would be of benefit to users at this level. 
  1825.  
  1826.             
  1827.  
  1828.  
  1829.                                                                          27
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.           Thanks for your attention - Bob Gowans. 
  1845.  
  1846.             
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.           Self Test Answers 
  1853.  
  1854.             
  1855.  
  1856.           a) Valid. 
  1857.  
  1858.           b) Valid 
  1859.  
  1860.           c) Valid 
  1861.  
  1862.           d) Invalid - there is a space character. 
  1863.  
  1864.           e) Invalid - program is a Pascal reserved word. 
  1865.  
  1866.           f) Invalid - does not start with a letter. 
  1867.  
  1868.           g) Invalid - Pascal identifiers do not allow a period. 
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.                                                                          28
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.                                       Conclusion
  1913.  
  1914.  
  1915.  
  1916.                Well, I have to  say, I'm much happier with the second issue
  1917.  
  1918.           of PNL. I'm glad I found the  time to include some code examples.
  1919.  
  1920.           I feel  it is  important to  have something  substantial for  the
  1921.  
  1922.           users  to  work with.  I  would  especially like  to  thank Craig
  1923.  
  1924.           Thurber and  Bob Gowans  for their  help by  including very  well
  1925.  
  1926.           written and  useful articles. I hope that in the future they, and
  1927.  
  1928.           others, will contribute more. It not only gives readers more than
  1929.  
  1930.           one point of  view in programming, but  it also takes a  big load
  1931.  
  1932.           off of my shoulders.
  1933.  
  1934.  
  1935.  
  1936.                I had originally planned an article  on sorting routines for
  1937.  
  1938.           this issue, but because of time  constraints I've been finding it
  1939.  
  1940.           very difficult  to proceed.  Instead of  delaying the  release of
  1941.  
  1942.           this issue further, I  have decided to go ahead  and release this
  1943.  
  1944.           issue and try to put the sorting article in a future issue.
  1945.  
  1946.  
  1947.  
  1948.                I would be a liar if I said I think the code I have provided
  1949.  
  1950.           is  fool-proof.  I've  tested  it, but  I  might  have overlooked
  1951.  
  1952.           something. If you do find a bug in the code I've provided, please
  1953.  
  1954.           let me know and I will include code fixes in following issues.
  1955.  
  1956.  
  1957.  
  1958.                My original plan  was to have more than one issue of PNL out
  1959.  
  1960.           a  month,  but   unless  I  start   getting  a  lot  of   article
  1961.  
  1962.           contributions,  that's  going   to  be   a  difficult  thing   to
  1963.  
  1964.  
  1965.                                                                          29
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.           accomplish. I'll tell you one thing that  would be really nice to
  1981.  
  1982.           have  is reviews written  by users. If  you would like  to review
  1983.  
  1984.           libraries and toolkits, feel  free to send those reviews in. I am
  1985.  
  1986.           also considering a  column called  'Bits and  Pieces' which  will
  1987.  
  1988.           have a bunch of small tips and techniques in pascal that  are too
  1989.  
  1990.           small  to deserve  articles  by themselves,  but  which would  be
  1991.  
  1992.           useful. 
  1993.  
  1994.  
  1995.  
  1996.                Another column  I would  like to  include is  a reader  mail
  1997.  
  1998.           column for comments and Q & A. 
  1999.  
  2000.  
  2001.  
  2002.                I am developing a rather large  distribution list and know I
  2003.  
  2004.           will  be racking  up pretty  hefty  phone bills  if it  gets much
  2005.  
  2006.           larger, so for the moment, here are the plans. I will only take a
  2007.  
  2008.           few more people  by node address  on the distribution list.  It's
  2009.  
  2010.           much easier for me  to send via BitNet, so I'll  be taking BitNet
  2011.  
  2012.           addresses until it gets too overbearing.  If you have a mainframe
  2013.  
  2014.           account  that is  on  BitNet, you  can pick  it up  from Simtel20
  2015.  
  2016.           either by using either of the following:
  2017.  
  2018.            TELL LISTSERV AT NDSUVM1 /PDGET PD:<MSDOS.PASCAL>PNLxxx.ZIP
  2019.  
  2020.           or
  2021.  
  2022.            TELL LISTSERV AT RPIECS /PDGET PD:<MSDOS.PASCAL>PNLxxx.ZIP
  2023.  
  2024.           where xxx is the issue #. (These are CMS commands. If you're on a
  2025.  
  2026.           Vax, the commands may  differ slightly.) It is also  available on
  2027.  
  2028.           GEnie.  I will  start putting the  FidoNet addresses,  State, and
  2029.  
  2030.           Area Code of people on the distribution list. Perhaps one of them
  2031.  
  2032.  
  2033.                                                                          30
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.           will be within local calling range of you. 
  2049.  
  2050.  
  2051.  
  2052.                What would be really  nice, is if some people out there with
  2053.  
  2054.           BitNet accounts in major cities would offer to receive a copy and
  2055.  
  2056.           spread it  around  their cities  for  me. It's  really  difficult
  2057.  
  2058.           getting a good distribution, but I'll work at it. Hopefully after
  2059.  
  2060.           a while distribution will take care of itself. i.e.  the PNL gets
  2061.  
  2062.           popular enough that it gets spread around well.
  2063.  
  2064.  
  2065.  
  2066.                Well, that  just about does it for  the second issue of PNL.
  2067.  
  2068.           Hope  it's been useful,  and like I  say and say  and say, please
  2069.  
  2070.           submit articles  and send suggestions. This newsletter is for the
  2071.  
  2072.           readers, not me. 
  2073.  
  2074.  
  2075.  
  2076.                                                 _Pete Davis
  2077.  
  2078.  
  2079.  
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.                                                                          31
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.                The Pascal NewsLetter is Copyrighted by Peter Davis. It
  2118.                may be freely  distributed in un-modified form,  but no
  2119.                charge whatsoever may be incurred on the recipient.
  2120.  
  2121.                The  Pascal  NewsLetter   can  be  obtained   from  the
  2122.                following locations:
  2123.  
  2124.                GEnie : General Electric Network for Information       
  2125.                        Exchange. It is located in the IBMPC filelist.
  2126.  
  2127.                Simtel: Internet address: 26.2.0.74 or Simtel20.ARPA It 
  2128.                        is located in the <MSDOS.PASCAL> directory.
  2129.  
  2130.                Programmer's Forum : This is the home of the PNL. Each
  2131.                                     issue can be found in the MAG     
  2132.                                     directory from the main area.
  2133.                                     The number is on the title page.
  2134.  
  2135.                If  you  would  like  to receive  back  issues  of  PNL
  2136.                directly  from  me,  send  a  diskette  and  $2.00  for
  2137.                shipping. Don't forget to include your address.
  2138.                Send your order to:
  2139.                   Peter Davis
  2140.                   4851 Brandywine St. NW
  2141.                   Washington, DC   20016
  2142.  
  2143.                If you are  a SysOp that  will regularly carry PNL  and
  2144.                would like to have your  bulletin board listed as such,
  2145.                here, send me a message either by postal mail or at one
  2146.                of the electronic  addresses given  on the title  page,
  2147.                with  your bulletin  board's  name, phone  number, your
  2148.                name, maximum baud rate, and a  description of up to 60
  2149.                characters of your bbs.
  2150.  
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.                                                                     32
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.                                   Distribution List
  2185.  
  2186.                The following is the phone numbers to  bulletin boards known
  2187.           to carry  PNL. If you would  like your bulletin  board's name and
  2188.           number  added to  or deleted  from this  list, please  send  me a
  2189.           message at one of my many addresses.
  2190.  
  2191.           The Programmer's Forum ................. Phone: (202) 966-3647 
  2192.           The Programmer's Forum is the home of the PNL.
  2193.  
  2194.           The Bored .............................. Phone: (512) 303-0471
  2195.  
  2196.           Classic City ........................... Phone: (404) 548-0726
  2197.  
  2198.           Theive's World ......................... Phone: (713) 463-8053
  2199.  
  2200.           Hippocampus ............................ Phone: (203) 484-4621
  2201.  
  2202.           Rogers State College BBS ............... Phone: (918) 341-8982
  2203.  
  2204.           The Foxtrot BBS ........................ Phone: (404) 793-2673
  2205.  
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.                                                                          33
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.