PROGRAM Create2;              { (C) 1991 John C. Leon   last updated 11/7/91 }

{
Creates an empty Btrieve file of record length 30 with 2 keys.  This empty
file is used in EXAMPLE1.PAS, and should be named EXAMPLE (no extension).
}

{$IFDEF production} {$D-,R-,L-,S-} {$ENDIF}

USES
   BTP;

VAR
   Counter,
   Counter1   : integer;
   MyFileSpec : PFileSpec;
   MyFileName : string;
   MyAltColSeq: PAltColSeq;

BEGIN
  MyFileSpec := new(PFileSpec);
  with MyFileSpec^ do
    begin
      {Create a fixed length, standard Btrieve file, with no pre-allocation, }
      {using UPPER.ALT as collating sequence for both keys.                  }
      RecLen   :=   30;   FileFlags := 0;
      PageSize :=  512;   PreAlloc  := 0;
      NumKeys  :=    2;
      fillchar(KeyArray, sizeof(KeyArray), 0);       {This line is MANDATORY!}
      {Key #0}
      with KeyArray[0] do
         begin
         KeyPos := 11; KeyLen := 20;
         {recommend ALWAYS using ExtType in KeyFlags assignment}
         KeyFlags := Duplicates + Modifiable + AltCol + ExtType;
         ExtKeyType:= BString; {always assign a value to this element}
         end;
      {Key #1}
      with KeyArray[1] do
         begin
         KeyPos :=  1; KeyLen := 10;
         KeyFlags := Duplicates + Modifiable + AltCol + ExtType;
         ExtKeyType := BString;
         end;
    end; {with MyFileSpec^ do}

  write('Enter name of file to create: ');
  readln(MyFileName);
  BStatus := CreateFile(MyFileName, MyFileSpec, 'Upper.Alt');
  dispose(MyFileSpec);
  if BStatus <> 0 then
    writeln('Error creating file.  Status = ', BStatus)
    else
    begin
    for Counter := 1 to length(MyFileName) do
       MyFileName[Counter] := upcase(MyFileName[Counter]);
    writeln('File ', MyFileName, ' created successfully.');
    end;

END.
