home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR36 / BTV200.ZIP / OWNER.PAS < prev    next >
Pascal/Delphi Source File  |  1993-12-18  |  2KB  |  96 lines

  1. {$X+}
  2. {$V-}
  3. { OWNER.PAS - demonstrate file creation with owner name (password)
  4.   Requires Turbo Pascal version 6.0, 7.0
  5. }
  6.  
  7. Uses
  8.   {$IFDEF WINDOWS}
  9.   WinCrt,
  10.   {$ELSE}
  11.   Crt,
  12.   {$ENDIF}
  13.   {$IFDEF VER70}
  14.   WinDos,
  15.   {$ELSE}
  16.   Dos,
  17.   {$ENDIF}
  18.   BtvConst,
  19.   Btv;
  20.  
  21.  
  22. type
  23.   ErrorType = Object(ErrorDisplay)
  24.     Function    Display(Error     : Integer;
  25.                         ErrorMsg  : String;
  26.                         OpCode    : Integer;
  27.                         OpCodeMsg : String;
  28.                         FileName  : PathStr
  29.                         ): ErrorAction;             Virtual;
  30.   end;
  31.  
  32.  
  33. var
  34.   F           : BtrieveFile;
  35.   ErrHandler  : ErrorHandler;
  36.   ErrDisplay  : ErrorType;
  37.   Buff        : Longint;
  38.  
  39. { Heres our error display object  }
  40. Function ErrorType.Display(Error     : Integer;
  41.                            ErrorMsg  : String;
  42.                            OpCode    : Integer;
  43.                            OpCodeMsg : String;
  44.                            FileName  : PathStr
  45.                            ): ErrorAction;
  46.   begin
  47.     ClrScr;
  48.     Writeln('Btrieve IO error for ' + FileName);
  49.     Writeln(Error,  ' - ', ErrorMsg);
  50.     Writeln(Opcode, ' - ', OpCodeMsg);
  51.     Writeln('Press any key ....');
  52.     ReadKey;
  53.     Display := erDone;  { just let the program continue }
  54.     ClrScr;
  55.   end;
  56.  
  57. begin
  58.   ClrScr;
  59.   CheckForBtrieve;
  60.  
  61.   { first make a error display }
  62.   ErrDisplay.Init;
  63.   { make an error handler, it needs a display object  }
  64.   ErrHandler.Init(@ErrDisplay);
  65.  
  66.   Writeln('Creating a file called PASSWORD.DAT');
  67.  
  68.   { init the file passing it the error handler and
  69.     address of our data buffer
  70.   }
  71.   F.Init('PASSWORD.DAT', @ErrHandler, @Buff, SizeOf(Buff));
  72.   { add a simple key }
  73.   F.AddKeySegment(1, 2, bExtended, bInteger, 0, 0);
  74.   { create the file }
  75.   F.Create(bNormal, SizeOf(Buff), 1024, 0, bNormal);
  76.   { open and assign an owner then close }
  77.   F.Open(bNormal, '');
  78.   F.SetOwner('DEMO', bNoAccess);
  79.   F.Close;
  80.  
  81.   { now open the file with the wrong owner name }
  82.   F.Open(bNormal, 'XXXX');
  83.   F.Close;
  84.  
  85.   { now open the file with the right owner name and
  86.     clear the owner name
  87.   }
  88.   F.Open(bNormal, 'DEMO');
  89.   F.ClearOwner;
  90.   F.Close;
  91.  
  92.   { now open the file with NO owner name }
  93.   F.Open(bNormal, '');
  94.   F.Close;
  95. end.
  96.