CapeSoft.Com
Clarion Accessories
File Explorer
Documentation
feFile
CapeSoft Logo

CapeSoft File Explorer feFile
Documentation

Download Latest Version
Installed Version Latest Version

Introduction

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.

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

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

Description

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
Parameter Description
errorMessageThe text of the error, warning or informational message.
methodNameThe name of the method that called ErrorTrap.
level The level of the of message, indicating the type of message that this is:
  • level = 0, indicates that this is an Error message
  • level = 2, indicates that this is a Warning message
  • level = 3, indicates that this is an informational message.
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

Cleanup ()

Description

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

Load (string fileName)

Description

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

Save (string CurrentPath, long CurrentControl)

Description

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

FileNameFromPath

FileNameFromPath (string fileName)

Description

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

PathOnly (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

Class Properties
binDataLen stringThe 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 longIf 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.