Navigation: ABC Library Reference > FileManager > FileManager Methods >====== TryOpen (try to open the file) ====== | |
TryOpen, PROC
The TryOpen method tells the FileManager the calling procedure is using the file, then OPENs the file if it is not already open. The TryOpen method does not attempt to handle errors that occur while opening the file.
The Open method provides a slightly different (automatic) alternative for opening files.
Implementation:
TryOpen tries to open the file. If it succeeds, it returns Level:Benign (declared in ABERROR.INC). If it fails, it returns the severity level of the error it encountered while trying to open the file. See Error Class for more information on severity levels.
Return Data Type: BYTE
Example:
PROGRAM
INCLUDE('ABFILE.INC') !declare FileManager class
MAP . !program map
GlobalErrors ErrorClass !declare GlobalErrors object
Access:Client CLASS(FileManager) !derive Access:Client object
Init PROCEDURE !prototype Access:File init
END
!file declaration
Client FILE,DRIVER('TOPSPEED'),PRE(CLI),CREATE,BINDABLE,THREAD
END
CODE
GlobalErrors.Init !initialize GlobalErrors object
Access:Client.Init !initialize Access:Client object
IF Access:Client.TryOpen !try to open the Client file
MESSAGE('Could not open the Client file') !handle the error yourself
RETURN
END
!program code
Access:Client.Close !close the Client file
Access:Client.Kill !shut down the Access:Client object
GlobalErrors.Kill !shut down the GlobalErrors object