home *** CD-ROM | disk | FTP | other *** search
- {
- :-------------------------------------------------------------------
- : BrSetUp1 is the companion to BrowseF1.
- : Copyright (c) - Ronald C. Schultz
- : RR 1, Nolalu, Ontario, Canada
- :-------------------------------------------------------------------
- : This unit is called by BrowseF1. It contains the initialization
- : code that is used in the browseF1 unit.
- :-------------------------------------------------------------------
- }
-
- Unit BrSetUp1;
- INTERFACE
- uses Crt;
-
- const
- FgBarColor = Black;
- BgBarColor = LightGray;
- FgColHeadColor = Blue;
- BgColHeadColor = Black;
- FgNormalColor = White;
- BgNormalColor = Black;
- EUpperCase = false;
- ELowerCase = false;
- ENoCasePreference = true;
-
- MaxFields = 10;
-
- FileName1 = 'samplef1.dat';
- BrowseFile1 : boolean = false;
- FileName2 = 'yourfile.dat';
- BrowseFile2 : boolean = false; (* use with Rec2 *)
-
- type
- str10 = string[10];
- FieldArray = array[1..MaxFields] of string[80];
- DataFields = record (* global variables *)
- fieldNm : str10;
- Width : byte;
- end;
-
- Rec1 = record
- FName : string[10];
- LName : string[15];
- age : byte;
- StAddress : string[25];
- City : string[20];
- Country : string[20];
- AcctNum : string[4];
- Balance : real;
- Comments : string[40];
- Deleted : string[1];
- end;
-
- (* put your data below *)
- rec2 = record
- end;
-
- BrFile1 = file of Rec1;
- BrFile2 = file of Rec2;
-
- FieldTypes = array[1..128] of DataFields;
-
- var
- FileVar1 : BrFile1;
- TempFile1 : BrFile1;
- RecVar1 : Rec1;
-
- FileVar2 : BrFile2; (* use with your data for rec2 *)
- TempFile2 : BrFile2;
- RecVar2 : Rec2;
-
- FieldVal : FieldArray; (* assign values of each record var *)
- Flds : FieldTypes; (* chars of each rec field *)
- NumFields : byte;
- FPos : longint;
-
- AppendPrompt : array[1..MaxFields] of string;
- AppendVar : FieldArray;
- AppendLength : array[1..MaxFields] of integer;
-
-
- Procedure InitBrowseVars;
- procedure GetRec;
- procedure Get_WriteEditRec(FldNum : integer;
- EditStr : string;
- OldFilePointerPos : LongInt;
- NewFilePointerPos : LongInt);
- Procedure AppendRec(AppendStrArray : FieldArray);
- Procedure DeleteRecs;
-
- IMPLEMENTATION
-
- {
- :-----------------------------------------------------------
- : DeleteRecs will delete those records that are marked with "*".
- : The "deleted" field should be marked for deletion in the
- : BrowseF1 unit. Fields will not be deleted unit they are packed
- : by selecting F4 while in the BrowseF1 unit.
- :-----------------------------------------------------------
- }
- Procedure DeleteRecs;
- begin
- if BrowseFile1 then
- begin
- assign(TempFile1,'temp.dat');
- rewrite(TempFile1);
- reset(FileVar1);
- while not Eof(FileVar1 ) do
- begin
- read(FileVar1,RecVar1);
- if RecVar1.Deleted <> '*' then write(TempFile1,RecVar1);
- end;
- reset(TempFile1);
- if BrowseFile1 then
- rewrite(FileVar1);
- while not eof(TempFile1) do
- begin
- read(TempFile1,RecVar1);
- write(FileVar1,RecVar1);
- end;
- erase(TempFile1);
- end;
-
- (* insert code below for second record *)
- (***************************************)
- (* if BrowseFile2 then *)
- (* begin *)
- (* end; *)
-
- end; (* DeleteRecs *)
- {
- :---------------------------------------------------
- : InitRec1 is called by BrowseF1 unit to set up column
- : heading names and to set the size of the fields displayed
- : on the screen.
- :----------------------------------------------------
- }
- Procedure InitRec1;
- begin
- fillchar(flds,sizeof(flds),0);
- flds[1].fieldNm := 'FNAME';
- flds[1].width := 10;
- flds[2].fieldNm := 'LNAME';
- flds[2].width := 15;
- flds[3].fieldNm := 'AGE';
- flds[3].width := 3;
- flds[4].fieldNm := 'ADDRESS';
- flds[4].width := 25;
- flds[5].fieldNm := 'CITY';
- flds[5].width := 20;
- flds[6].fieldNm := 'COUNTRY';
- flds[6].width := 20;
- flds[7].fieldNm := 'ACCTNUM';
- flds[7].width := 4;
- flds[8].fieldNm := 'BAL';
- flds[8].width := 9;
- flds[9].fieldNm := 'COMMENTS';
- flds[9].width := 40;
- flds[10].fieldNm := 'DELSTAT';
- flds[10].width := 1;
- (* This is limited to 21 fields *)
- NumFields := 10;
-
- {
- :------------------------------------------------------------
- : The BrowseF1 unit can be used to append new records.
- : The following code is used to label each data entry prompt
- : The append screen can only accommodate 21 fields which is
- : basically one screen of fields. The prompt and field length
- : must be entered below for each field.
- :------------------------------------------------------------
- }
- AppendPrompt[1] := 'First Name......';
- AppendLength[1] := 10;
- AppendPrompt[2] := 'Last Name.......';
- AppendLength[2] := 15;
- AppendPrompt[3] := 'Age.........';
- AppendLength[3] := 2;
- AppendPrompt[4] := 'Address.........';
- AppendLength[4] := 25;
- AppendPrompt[5] := 'City............';
- AppendLength[5] := 20;
- AppendPrompt[6] := 'Country.........';
- AppendLength[6] := 20;
- AppendPrompt[7] := 'Account number..';
- AppendLength[7] := 4;
- AppendPrompt[8] := 'Balance.........';
- AppendLength[8] := 9;
- AppendPrompt[9] := 'Comments........';
- AppendLength[9] := 40;
- AppendPrompt[10] := 'Delete Rec.....';
- AppendLength[10] := 1;
- end; (* initrec1 *)
-
- (* insert code for rec2 below *)
- (******************************)
- Procedure InitRec2;
- begin
- end; (* InitRec2 *)
- (******************************)
-
- Procedure InitBrowseVars;
- begin
- if BrowseFile1 then InitRec1;
- (* if BrowseFile2 then initRec2; *)
- end;
-
- (* GetRec1 reads records from file for display in Browsef1 Unit *)
- procedure GetRec1;
- begin
- read(FileVar1,RecVar1);
- {
- :-------------------------------------------------------------
- : all fields must be converted to a string before they are
- : sent to the browse unit
- : ------------------------------------------------------------
- }
- fillchar(FieldVal,sizeof(FieldVal),0);
- FieldVal[1] := RecVar1.fname;
- FieldVal[2] := RecVar1.lname;
- str(RecVar1.age,FieldVal[3]);
- FieldVal[4] := RecVar1.staddress;
- FieldVal[5] := RecVar1.city;
- FieldVal[6] := RecVar1.country;
- FieldVal[7] := RecVar1.acctnum;
- str(RecVar1.balance:6:2,FieldVal[8]);
- FieldVal[9] := RecVar1.comments;
- FieldVal[10] := RecVar1.Deleted;
- AppendVar := FieldVal;
- end; (* GetRec1 *)
-
- (* insert code for rec2 *)
- (************************)
- procedure GetRec2;
- begin
- end;
-
- procedure GetRec;
- begin
- if BrowseFile1 then GetRec1;
- (* if BrowseFile2 then GetRec2; *)
- end;
- {
- :-------------------------------------------------------------
- : AppendRec receives record staring data from BrowseF1 and
- : writes the data to the file. All data must be re-converted
- : from string data to the appropriate data type before writing
- : to the file.
- :-------------------------------------------------------------
- }
- Procedure AppendRec(AppendStrArray : FieldArray);
- var
- e : integer;
- begin
- if BrowseFile1 then
- begin
- RecVar1.FName := AppendStrArray[1];
- RecVar1.LName := AppendStrArray[2];
- val(AppendStrArray[3],RecVar1.age,e);
- RecVar1.StAddress := AppendStrArray[4];
- RecVar1.City := AppendStrArray[5];
- RecVar1.Country := AppendStrArray[6];
- RecVar1.AcctNum := AppendStrArray[7];
- val(AppendStrArray[8],RecVar1.Balance,e);
- RecVar1.Comments := AppendStrArray[9];
- RecVar1.Deleted := AppendStrArray[10];
- Seek(FileVar1, FileSize(FileVar1));
- write(FileVar1,RecVar1);
- end;
- {
- :-------------------------------
- : insert code for rec2 here
- (*****************************)
- : if BrowseFile2 then
- : begin
- : end;
- :-------------------------------
- }
-
- end; (* AppendRec *)
- {
- :---------------------------------------------------------
- : Get_WriteEditRec gets the edited record from BrowseF1.
- : Data comes from BrowseF1 as a string. Data must be
- : converted to the appropriate data type before writing
- : to the file.
- :---------------------------------------------------------
- }
- procedure Get_WriteEditRec(FldNum : integer;
- EditStr : string;
- OldFilePointerPos : LongInt;
- NewFilePointerPos : LongInt);
- var
- Rec1Copy : Rec1;
- (* Rec2Copy : Rec2; *)
- e : integer;
- begin
- (* edit a single field *)
- if BrowseFile1 then
- begin
- seek(FileVar1,NewFilePointerPos-1);
- read(FileVar1,Rec1Copy);
- case FldNum of
- 1 : Rec1Copy.FName := EditStr;
- 2 : Rec1Copy.LName := EditStr;
- 3 : val(EditStr,Rec1Copy.age,e);
- 4 : Rec1Copy.StAddress := EditStr;
- 5 : Rec1Copy.City := EditStr;
- 6 : Rec1Copy.Country := EditStr;
- 7 : Rec1Copy.AcctNum := EditStr;
- 8 : val(EditStr,Rec1Copy.Balance,e);
- 9 : Rec1Copy.Comments := EditStr;
- 10: Rec1Copy.Deleted := EditStr[1];
- end;
- seek(FileVar1,NewFilePointerPos-1);
- write(FileVar1,Rec1Copy);
- seek(FileVar1,OldFilePointerPos);
- end; (* BrowseFile1 *)
- {
- :----------------------------------
- : (* insert code for rec2 below
- : (******************************)
- : if BrowseFile2 then
- : begin
- : end;
- :----------------------------------
- }
-
- end; (* Get_WriteEditRec *)
-
- begin
- end.
-
-