home *** CD-ROM | disk | FTP | other *** search
- (*----------------------------------------------------------------------------
-
- The unit LOOKER permits its user to point and shoot using TAccess index
- and or data files. Essentially, it pops up a window displaying the
- index file key and any associated data from the data file. It has a moving
- bar which highlights the specific record needed. A <CR> returns the
- data reference (record number) for further use in the program.
- Additionally, it allows for searches in the index, by permitting the user
- to enter in a key or partial key. A small sample program is included at
- the bottom of this file. This file can be compiled as is.
-
- This unit requires Turbo Professional.
-
- The unit has a public procedure 'MakeParmStr', which is called to build
- a parameter used in the primary function 'Look'.
-
- The following is a description of the public variable, procedure, and
- function:
-
-
-
-
- var
- Fields : string;
-
- (
- This variable is used as a parameter in Look. It is constructed
- using MakeParmStr. It is built by calling it once for each field
- you want to see displayed in the window. If you only want to
- display the key from the index file, then this it should be set
- to null (Fields := '')
- )
-
- procedure makeparmstr(Dtype:word;
- var field;
- Mask:string);
-
- (
- This procedure builds a string which serves as a kluge for an unknown
- number of parameters for Look. You may include as many data fields as
- you desire, but you must call this procedure once for each of those data
- fields. If you do not want to display any fields from the data file,
- no calls to this procedure are necessary.
-
- DType: This field is used to determine the type of the field:
-
- 1: String
- 2: Longint
- 3: Integer
- 4: Real
- 5: Char
-
- NOTE: This unit has NOT been tested thouroughly with
- fields types other than strings!
-
- Field: This field is constructed using MakeParmStr. Be sure
- to set it to null prior to calling MakeParmStr.
-
- Mask : You may set up a mask on your data fields by inserting
- delimeters in this field.
-
- For example, if the field is a date:
- the field may reside on disk as 31121989,
- then a mask such as '2X/2X4X' will ensure the field is
- displayed as '31/12/1989'
-
- All integers are interpreted as lengths, and should precede
- any mask characters. Mask characters are: @,*,#,x,X.
- All of these characters are treated the same. They do not
- signify any charater type and can be used interchangeably.
- Using 'X's usually will suffice. Any characters but integers
- and mask characters will be interpreted as delimeters.
-
- The overall length of the mask will determine how many
- characters are displayed. If the mask is shorter than
- the field, the displayed field will be truncated.
-
- function Look(var KFile :IndexFile;
- var DFile : DataFile;
- var Rcrd;
- FldStr: string;
- Depth, X, Y: integer;
- InKey:string;
- KeyMask: String): Longint;
-
-
- Following is a brief explanation of the parameters for Look:
-
- KFile: The variable for the Key (index) file.
- DFile: The variable for the Data file.
- Rcrd : The variable for the record used in the Data file
- FldStr: Use the Field variable that was constructed using
- MakeParmStr
- Depth: The desired depth for the window
- X,Y : The X,Y coordinates for the upper right hand corner
- of the window. Look automatically determines the width.
- InKey: Use this field if you want Look to look for a specific
- key on entry to the function.
- KeyMask: This is a mask for the key only. It operates exactly
- like the Mask parameter in MakeParmStr.
- The first field displayed is always the Key.
-
-
- NOTE: Displays that will result past the 80th character will be truncated.
-
- ---------------------------------------------------------------------------*)
- program lookit;
- uses Crt,taccess,looker;
-
- type
- CompType = RECORD
- RECSTAT : longint;
- COMP_POC : STRING[25];
- COMP_REMARKS2 : STRING[70];
- Company : STRING[25];
- COMP_ADD1 : STRING[25];
- COMP_ADD2 : STRING[25];
- COMPANY_ID : STRING[10];
- COMP_CITY : STRING[25];
- COMP_STATE : STRING[2];
- COMP_ZIP : STRING[9];
- COMP_PHONE : STRING[10];
- COMP_PHEXT : STRING[5];
- COMP_REMARKS : STRING[70];
- END;
-
- var
- DatRef : longint; {used for the record number}
- CompRec : CompType;
- DatFile : DataFile;
- KeyFile : IndexFIle;
-
- begin
- OpenFile(DatFile, 'Comp.dat',SizeOf(CompRec));
- OpenIndex(KeyFile,'Comp.K1',12, Duplicates);
- Fields := '';
- MakeParmStr(1,CompRec.Company_ID,'10x'); {mask will truncate}
- MakeParmStr(1,CompRec.Comp_State,'xx'); {integers aren't necessary}
- MakeParmStr(1,CompRec.Comp_Phone,'(###)3#-4#'); {set up the mask to present
- the phone # in a more
- readable format}
-
- DatRef := Look(KeyFile,DatFile,CompRec,Fields,8,7,7,'Quart','12X');
- {Begin the display by looking for any Key beginning with^}
- {Return the data reference number. Usually for GetRec}
-
- CloseFile(DatFile);
- CloseIndex(KeyFile);
- end.
-
- This sample program displays the key and three data fields. You may
- want to experiment with other fields. NOTE: Some of the fields do
- not have data in them. For a thorough example, I recommend using your
- own files by replacing the record definition, data names, and file defi-
- nitions in this source.