File Explorer :: feFile Class reference
  Capesoft FileExplorer - Click to open the CapeSoft Home page in a new window.
Class Reference Icon
 
Version Version Number
     

Introduction to the feFile class.

The feFile class provides generic file loading and saving. It allows any file to be loaded from disk into memory, and any data in memory to be saved to a file. Both saving and loading can be done by calling a one method - feFile.Load() and feFile.Save() respectively.

 

The feFile Class
 

Introduction

Class Reference Icon Class Methods

Destruct Deallocates memory
CleanUp Force early cleanup/deallocation
Load Load a file from disk into memory
Save Save from memory to disk
FileNameFromPath Return the file name only when passed the entire path.
PathOnly Return the directory name when passed the entire path
ErrorTrap Trap and handle errors

Class Reference Icon Class Properties

binDataLen
binData
winErrorCode


 
     


Class Methods

The feFile class provides a simple mechanism for loading and saving files to and from disk.

Using the feFile Class is very simple:

htmlFile      class(feFile)
             
end
  code
    if not htmlFile.Load(fileName)
        Message('Load', 'Loading the file failed.')
    end

    ! The loaded file is stored in the htmlFile.binData property
    ! and htmlFile.binDataLen is the size of the buffer allocated


    !--- Write the file back to disk
    htmlFile.Save(fileName)

 

When errors occur the methods call the ErrorTrap() method with the warning or error. This allows the error to be handled, and by default will log the error the the system debug output.

To display ErrorTrap messages set the .logging property of the class to 1 and the .level property to the level of logging required (0 for errors only, 1 to include warnings and 2 for all messages including errors, warnings and information). The output can then be viewed using the free DebugView utility from Microsoft (www.sysinternals.com).

 


ErrorTrap Procedure (string errorMesssage, string methodName, long level=0)

The ErrorTrap() method is called each time an error occurs, or a warning is issued, or there is additional information available that can be helpful for debugging and diagnostic purposes. The Level parameter is set dependant on the type of message. The .logging property of the class determines whether these messages are logged to the system debug output (.logging =1) and the .level property of the class determines which messages are logged (.level=0 logs only errors, .level=1 logs errors and warnings, .level=2 logs all messages.

Parameters

errorMessage
The text of the error, warning or informational message.

methodName
The name of the method that called ErrorTrap.

level
The level of the of message, indicating the type of message that this is:

Notes

The passed level parameter is checked against the .level property of the class. If the level is passed is less than or equal to .level the error is logged (if the .logging property is set to a no zero value). By default the .level property is zero, and hence only error messages are logged. To also log warning messages set .logging to 1 and to log all messages set .logging to 2.

 

 

Cleanup procedure ()

Cleans up, deallocates all memory, and disposes of all interfaces. Typically this will be called automatically by the destructor, however if you are using New() and Dispose() to dynamically create and destroy the object you should call Cleanup() before calling Dispose().

 

 

Load procedure (string fileName)

Loads the specified file into memory. The contents of the string are stored in the .binData property and the length of the data is stored in the .binDataLen property.

 

 

Save procedure (string CurrentPath, long CurrentControl)

This method is deprecated, use the #Load() method.

 

 

FileNameFromPath procedure (string fileName)

Returns just the name of the file, when passed the entire file path and name.

For example if 'C:\Temp\foo.txt' was passed this method would return 'foo.txt'

 

 

PathOnly procedure (string fileName)

Returns just the path when passed the entire file path and name.

For example if 'C:\Temp\foo.txt' was passed, this method would return 'C:\temp\'

 

 

 

feFile Class Properties

binDataLen string

The size of the .binData string. When the Save() method is called this is set to the size of the data written to disk, and when Load() is called this is set to the length of the .binData string used to store the loaded data.

 


binData string

Stores the data to be saved to or loaded from file. The class automatically allocates this to the correct size when calling load. When calling Save this string is written to the specified file name. For saving, this string can be disposed and the new'd to the correct size. After doing so set the .binDataLen to the new size of the string before calling Save().

 


winErrorCode long

If the file loading fails becuase of a Windows API error then the ErrorTrap() method is called and the API error code is stored in this property.

 


 

 


Copyright © Capesoft Software (Pty) Ltd