home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / BTP20.ZIP / CREATE1.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-06-10  |  3.0 KB  |  84 lines

  1. PROGRAM Create1;              { (C) 1993 John C. Leon    last updated 6/8/93 }
  2.  
  3. {
  4. Creates an arbitrarily structured empty Btrieve file of record length 38 with
  5. 3 keys.  This file, which you must name EXAMPLE when you run this program,
  6. will be used by the EXAMPLE1 and EXAMPLE2 programs.  The keys are interpreted 
  7. by the EXAMPLE1 and EXAMPLE2 programs as follows:
  8.  
  9.    Key 0: 20 positions, an LString (Pascal string), representing LAST NAME
  10.    Key 1: 10 positions, an LString (Pascal string), representing FIRST NAME
  11.    Key 2:  8 positions, a Float (which when sized to 8 positions is an IEEE
  12.                                  double, and can be used directly as such in
  13.                                  Pascal or C/C+), representing Salary
  14.  
  15. Illustrates the use of PFileSpecObj in the BTP unit to greatly assist in
  16. setting up the filespec in memory required for the CreateFile function.  See
  17. CREATE2.PAS for sample code using the CreateFile function with an alternate
  18. collating sequence and an owner name, and for sample code for adding
  19. supplemental indexes.
  20. }
  21.  
  22. {$IFDEF production} {$D-,R-,L-,S-} {$ENDIF}
  23.  
  24. USES
  25.    BTP;
  26.  
  27. VAR
  28.    Counter,
  29.    Counter1   : integer;
  30.    MyFileSpec : PFileSpecObj;
  31.    MyFileName : string;
  32.  
  33. BEGIN
  34.    if not IsBtrieveLoaded then
  35.       begin
  36.       writeln;
  37.       writeln('Please load Btrieve before running this program.');
  38.       halt(1);
  39.       end;
  40.  
  41.    write('Enter name of file to create: ');
  42.    readln(MyFileName);
  43.    if MyFileName = '' then
  44.       begin
  45.       writeln('No filename entered...aborting');
  46.       halt(2);
  47.       end;
  48.  
  49.    {Setup the file specs as: record length  38,
  50.                              page size     512,
  51.                              # keys          3,
  52.                              file flags      0,
  53.                              pre-allocation  0 }
  54.  
  55.    {MyFileSpec internally puts all parameters into a properly formatted
  56.     memory buffer, accessible as MyFileSpec^.Specs}
  57.  
  58.    MyFileSpec := new(PFileSpecObj, Init(38, 512, 3, 0, 0,
  59.                      NewKeySpec(11, 20, Duplicates or Modifiable or ExtType,
  60.                                 BLString,
  61.                      NewKeySpec(1, 10, Duplicates or Modifiable or ExtType,
  62.                                 BLString,
  63.                      NewKeySpec(31, 8, Duplicates or Modifiable or ExtType,
  64.                                 BFloat,
  65.                                 nil)))));
  66.  
  67.    BStatus := CreateFile(MyFileName, MyFileSpec^.Specs, '', '', 0);
  68.                               {                         |   |   | }
  69.                               { no alt coll sequence    -   |   | }
  70.                               { no owner name               -   | }
  71.                               { owner name access               - }
  72.    
  73.    dispose(MyFileSpec, Done);
  74.    
  75.    if BStatus <> 0 then
  76.      writeln('Error creating file.  Status = ', BStatus)
  77.      else
  78.      begin
  79.      for Counter := 1 to length(MyFileName) do
  80.         MyFileName[Counter] := upcase(MyFileName[Counter]);
  81.      writeln('File ', MyFileName, ' created successfully.');
  82.      end;
  83. END.
  84.