home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / SDEFS1.ZIP / SETDEFS.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-12-06  |  5.4 KB  |  149 lines

  1.  
  2.  
  3.  
  4. Program SetDefs; {Sample `install' program for use with the DEMO.PAS     }
  5.                  {program included in this archive.                      }
  6.                  {This source code and software is released to the public}
  7.                  {domain for non-commercial users, 1988 John Majkrzak.   }
  8.                  {All Rights Reserved.  Request permission for commercial}
  9.                  {use or reprint.                                        }
  10.                  {  John Majkrzak           CIS 76617,264                }
  11.                  {  1880 Todd Dr.           Ph# (612)636-9761            }
  12.                  {  Arden Hills, MN 55112                                }
  13.  
  14.     {$M 4000, 66000, 88000}
  15.  
  16.     Uses
  17.       CRT, DOS,
  18.       sDefs;     { << This TPU does much of the hard work required to
  19.                   get a install program put together.  Just use it as
  20.                   you see it used in this sample installation program.
  21.                  }
  22.  
  23.     Type
  24.       DefRecType = Record
  25.         St: String[32];
  26.         Yr,Mth,Day:   Word;
  27.       end;
  28.  
  29.        {------------------------------------------------------------------}
  30.        {The constant block in your INSTALL program must match EXACT to the}
  31.        {one in the actual program.  Use only one block of declarations all}
  32.        {under one CONST statement.  Declare every variable type. Don't say}
  33.        {'MyNumber = 144;' say, `MyNumber: Word = 144;'.                   }
  34.        {The idHeader is used to identify where your variables are located.}
  35.        {It must be a string.  This is one of the few changes you may need }
  36.        {to make to your source code when adapting this INSTALL routine for}
  37.        {your own use.                                                     }
  38.  
  39.        {These variables must be set AFTER you read in the existing        }
  40.        {variable block from your program for any changes you want to keep.}
  41.        {Only the current value of `idHeader' must exactly match the       }
  42.        {current value of idHeader in the object program.                  }
  43.        {------------------------------------------------------------------}
  44.  
  45.     Const
  46.       idHeader:   String[8]  = 'XmtSpot ';
  47.       DefaultRec: DefRecType =
  48.         (
  49.           St:  ' ';             { << These values do not matter since they}
  50.           Yr:  1986;            { get overwritten when you `ReadMemBlk().'}
  51.           Mth: 10;
  52.           Day: 10
  53.         );
  54.       BgColor:  Byte = 0;
  55.       FgColor:  Byte = 0;
  56.       LastByte: Byte = 0;  {This is only used to mark last byte of block, }
  57.                            {see it in use with vbSize at start of program.}
  58.  
  59.     Const
  60.       LoadPrgName   = 'DEMO.EXE'; {Add a path designation or change the}
  61.       SavePrgName   = 'DEMO.EXE'; {name for easier testing.}
  62.  
  63.     Var
  64.       J:              Word; {Global iteration variable.}
  65.       vbSize:         Word; {Size of CONST block of default variables.}
  66.       Ch:             Char;
  67.  
  68.   Procedure Beep;
  69.     Begin Sound(880); Delay(110); NoSound;
  70.   end;
  71.  
  72.   Procedure PurgeKeyboard;
  73.     Var
  74.       Ch: Char;
  75.     Begin While Keypressed do Ch:= ReadKey;
  76.   end;
  77.  
  78.   Function AnsYN: Char;
  79.     Const
  80.       YNset: Set of char = ['Y','N'];
  81.     Var
  82.      Ch: Char;
  83.     Begin
  84.     PurgeKeyBoard;
  85.     Repeat
  86.       Ch:= UpCase(ReadKey); AnsYN:= Ch;
  87.       PurgeKeyboard;
  88.       If Ch IN YNset then EXIT else beep;
  89.     until FALSE;
  90.   end;
  91.  
  92.   Procedure ErExit;
  93.     Begin
  94.     GoToXY(1,WhereY); ClrEOL;
  95.     Write(ErSt); {The error report string is provided by sDefs.TPU}
  96.     delay(4000);
  97.     Halt;
  98.   end;
  99.  
  100. (* -------------------------------------------------------------------------
  101.     EXPLANATION OF NUMBERED COMMENTS
  102.  {1} vbSize is set equal to size in bytes of the block of variables in need
  103.      of adjustments.
  104.  {2} The program gets loaded into heapspace.
  105.  {3} Locate the block within your program by having it search for the
  106.      identifier string.
  107.  {4} Copy block of `vbSize' bytes from program just loaded.
  108.  {5} Make any needed changes to your variables.
  109.  {6} Write the changed settings back to where the block came from.
  110.  {7} Save the program.  The file date of original program is intact.
  111.  ------------------------------------------------------------------------ *)
  112.  
  113.   Begin
  114.   WriteLn;
  115. {1} vbSize:= Ofs(LastByte)-Ofs(idheader); {Segments will be equal.}
  116.     Write('Loading program file.');
  117. {2} If NOT PrgFileLoaded(LoadPrgName) then ErExit;
  118.     GoToXY(1,WhereY); ClrEOL;
  119.     Write('Searching for default record block');
  120. {3} If NOT DefRecFound(@idHeader, SizeOf(idHeader) ) then ErExit;
  121. {4} ReadMemBlk(@idheader, vbSize);
  122.     GoToXY(1,WhereY); ClrEOL;
  123.     With DefaultRec do
  124.       WriteLn('Current file written: ',Mth,'-',Day,'-',Yr);
  125.     Repeat
  126. {5}   BgColor:= Green;
  127.       FgColor:= Red;     {When DEMO is compiled these are Yellow-on-Blue.}
  128.       TextColor(FgColor);
  129.       TextBackground(BgColor);
  130.       WriteLn;
  131.       WriteLn('Current demonstration string: ',DefaultRec.St);
  132.       WriteLn;
  133.       Write('New string? ');
  134. {5}   ReadLn(DefaultRec.St);
  135.       WriteLn;
  136.       WriteLn('Prepare disk drive to receive file.');
  137.       Write  ('Press any key to continue.');
  138.       PurgeKeyboard;
  139.       Ch:= ReadKey;
  140.       With DefaultRec do GetDate(Yr, Mth, Day, J);
  141. {6}   WriteMemBlk(@idHeader, vbSize);
  142. {7}   If NOT PrgFileSaved(SavePrgName) then ErExit;
  143.       WriteLn;
  144.       Write('Do another, Y/N?');
  145.       Ch:= AnsYN;
  146.     until Ch = 'N';
  147.     WriteLn;
  148.     WriteLn('Finished OK');
  149.  END.