home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / LOOKER.ZIP / LOOKIT.DOC < prev   
Encoding:
Text File  |  1989-10-09  |  6.1 KB  |  155 lines

  1. (*----------------------------------------------------------------------------
  2.  
  3. The unit LOOKER permits its user to point and shoot using TAccess index
  4. and or data files.  Essentially, it pops up a window displaying the
  5. index file key and any associated data from the data file.  It has a moving
  6. bar which highlights the specific record needed.  A <CR> returns the
  7. data reference (record number) for further use in the program.
  8. Additionally, it allows for searches in the index, by permitting the user
  9. to enter in a key or partial key.  A small sample program is included at
  10. the bottom of this file.  This file can be compiled as is.
  11.  
  12. This unit requires Turbo Professional.
  13.  
  14. The unit has a public procedure 'MakeParmStr', which is called to build
  15. a parameter used in the primary function 'Look'.
  16.  
  17. The following is a description of the public variable, procedure, and
  18. function:
  19.  
  20.  
  21.  
  22.  
  23. var
  24.   Fields : string;
  25.  
  26. (
  27.  This variable is used as a parameter in Look.  It is constructed
  28.  using MakeParmStr.  It is built by calling it once for each field
  29.  you want to see displayed in the window.  If you only want to
  30.  display the key from the index file, then this it should be set
  31.  to null (Fields := '')
  32. )
  33.  
  34. procedure makeparmstr(Dtype:word;
  35.                       var field;
  36.                       Mask:string);
  37.  
  38. (
  39.  This procedure builds a string which serves as a kluge for an unknown
  40.  number of parameters for Look.  You may include as many data fields as
  41.  you desire, but you must call this procedure once for each of those data
  42.  fields.  If you do not want to display any fields from the data file,
  43.  no calls to this procedure are necessary.
  44.  
  45.         DType:  This field is used to determine the type of the field:
  46.  
  47.                 1: String
  48.                 2: Longint
  49.                 3: Integer
  50.                 4: Real
  51.                 5: Char
  52.  
  53.                 NOTE:  This unit has NOT been tested thouroughly with
  54.                 fields types other than strings!
  55.  
  56.         Field:  This field is constructed using MakeParmStr.  Be sure
  57.                 to set it to null prior to calling MakeParmStr.
  58.  
  59.         Mask : You may set up a mask on your data fields by inserting
  60.                delimeters in this field.
  61.  
  62.                For example, if the field is a date:
  63.                the field may reside on disk as 31121989,
  64.                then a mask such as '2X/2X4X' will ensure the field is
  65.                displayed as '31/12/1989'
  66.  
  67.                All integers are interpreted as lengths, and should precede
  68.                any mask characters.  Mask characters are: @,*,#,x,X.
  69.                All of these characters are treated the same.  They do not
  70.                signify any charater type and can be used interchangeably.
  71.                Using 'X's usually will suffice.  Any characters but integers
  72.                and mask characters will be interpreted as delimeters.
  73.  
  74.                The overall length of the mask will determine how many
  75.                characters are displayed.  If the mask is shorter than
  76.                the field, the displayed field will be truncated.
  77.  
  78. function Look(var KFile :IndexFile;
  79.               var DFile : DataFile;
  80.               var Rcrd;
  81.               FldStr: string;
  82.               Depth, X, Y: integer;
  83.               InKey:string;
  84.               KeyMask: String): Longint;
  85.  
  86.  
  87. Following is a brief explanation of the parameters for Look:
  88.  
  89.               KFile:  The variable for the Key (index) file.
  90.               DFile:  The variable for the Data file.
  91.               Rcrd :  The variable for the record used in the Data file
  92.               FldStr: Use the Field variable that was constructed using
  93.                       MakeParmStr
  94.               Depth:  The desired depth for the window
  95.               X,Y  :  The X,Y coordinates for the upper right hand corner
  96.                       of the window. Look automatically determines the width.
  97.               InKey:  Use this field if you want Look to look for a specific
  98.                       key on entry to the function.
  99.               KeyMask: This is a mask for the key only. It operates exactly
  100.                       like the Mask parameter in MakeParmStr.
  101.                       The first field displayed is always the Key.
  102.  
  103.  
  104. NOTE:  Displays that will result past the 80th character will be truncated.
  105.  
  106. ---------------------------------------------------------------------------*)
  107. program lookit;
  108. uses  Crt,taccess,looker;
  109.  
  110. type
  111. CompType = RECORD
  112.   RECSTAT : longint;
  113.   COMP_POC             : STRING[25];
  114.   COMP_REMARKS2        : STRING[70];
  115.   Company              : STRING[25];
  116.   COMP_ADD1            : STRING[25];
  117.   COMP_ADD2            : STRING[25];
  118.   COMPANY_ID           : STRING[10];
  119.   COMP_CITY            : STRING[25];
  120.   COMP_STATE           : STRING[2];
  121.   COMP_ZIP             : STRING[9];
  122.   COMP_PHONE           : STRING[10];
  123.   COMP_PHEXT           : STRING[5];
  124.   COMP_REMARKS         : STRING[70];
  125. END;
  126.  
  127. var
  128.   DatRef : longint;     {used for the record number}
  129.   CompRec : CompType;
  130.   DatFile : DataFile;
  131.   KeyFile : IndexFIle;
  132.  
  133. begin
  134.     OpenFile(DatFile, 'Comp.dat',SizeOf(CompRec));
  135.     OpenIndex(KeyFile,'Comp.K1',12, Duplicates);
  136.     Fields := '';
  137.     MakeParmStr(1,CompRec.Company_ID,'10x');        {mask will truncate}
  138.     MakeParmStr(1,CompRec.Comp_State,'xx');         {integers aren't necessary}
  139.     MakeParmStr(1,CompRec.Comp_Phone,'(###)3#-4#'); {set up the mask to present
  140.                                                      the phone # in a more
  141.                                                      readable format}
  142.  
  143.     DatRef := Look(KeyFile,DatFile,CompRec,Fields,8,7,7,'Quart','12X');
  144.   {Begin the display by looking for any Key beginning with^}
  145.   {Return the data reference number.  Usually for GetRec}
  146.  
  147.     CloseFile(DatFile);
  148.     CloseIndex(KeyFile);
  149. end.
  150.  
  151. This sample program displays the key and three data fields.  You may
  152. want to experiment with other fields.  NOTE:  Some of the fields do
  153. not have data in them.  For a thorough example, I recommend using your
  154. own files by replacing the record definition, data names, and file defi-
  155. nitions in this source.