|
|
| Products - Icetips Utilities - Core Class tutorial |
Core Class (ITCoreClass)
The Core Class contains 23 methods as of version 1.1.2351 that was released on April 15, 2009.
The Core class is what all the other classes are based on so it has some very basic methods
that are used all over the place in the other classes.
Below are short tutorials on how to accomplish various things with this class. The tutorials are short and demonstrate
simple use of the methods. For more detailed documentation of the string class please see
the online documentation.
Getting and Seting file information
Get temporary filenames and temporary folder
Getting and setting file information
When dealing with files it is often desirable to be able to know if a file has the read-only attribute set for example.
In some cases it can also be useful to be able to change the attributes of a files, for example to change a hidden
file to be not hidden or to mark a file to be read-only.
The Core class has several methods to get information about files and folders. To start with, lets take a look at the
GetFileAttrib and SetFileAttrib.
Example:
ITC ITCoreClassClass
RO Byte
HI Byte
SY Byte
Code
ITC.GetFileAttrib('C:\Temp\Filename.txt',RO,HI,SY)
Message('Read-Only = ' & RO & '|Hidden = ' & HI & '|System File = ' & SY)
This will give us the attributes of this file. The GetFileAttrib and SetFileAttrib only retrieve and
set the Read-only, Hidden and System attributes.
Example:
ITC ITCoreClassClass
RO Byte
HI Byte
SY Byte
Code
RO = True
HI = False
SY = False
ITC.SetFileAttrib('C:\Temp\Filename.txt',RO,HI,SY) !! Set the attributes
!! Set it to false to make sure we are getting the information from the file.
RO = False
ITC.GetFileAttrib('C:\Temp\Filename.txt',RO,HI,SY) !! Get the attributes
Message('Read-Only = ' & RO & '|Hidden = ' & HI & '|System File = ' & SY)
Now you should see that the Read-only has been set on the file. Take a look in Windows Explorer
to make sure.
There are two other functions that give us information about files. IsFolder and IsFileInUse will
let us know if a filename is a folder or a file and IsFileInUse will tell us if a specified file
can be written to or not.
When dealing with foldernames it is sometimes very important to be able to distinguish if a filename
is a foldername or not. With valid foldernames such as MyFile.TXT it could lead to all sorts of
problems if we passed this into a method or function that attempted to write to the file. In this
case the filename is perfectly valid for both a folder and a file. This is where IsFolder comes to the
rescue. It will ONLY return True if the filename passed to it is a name of a folder by getting the
attribute of the file with the GetFileAttributes api call.
Example:
ITC ITCoreClass
FN CString(2049)
Code
FN = 'C:\temp\myfile.txt'
If Not ITC.IsFolder(Fn)
Remove(Fn)
End
In this case the file would only be removed if it is a regular file, not if it is a folder. This can
be very useful when you are writing generic methods that can take a parameter with a filename or
a foldername and need to work differently depening on if the filename is actually a name of a folder or a file.
Get temporary filenames and temporary folder
Sometimes you need to place some data temporarily into a file and then remove the file. Rather
than create those files in the application folder, which can cause virtualization to kick in, or
in your data folder, it can be very convenient to write those files to the temporary folder.
The GetTempFilename and GetTempFolder methods are designed to take care of that.
GetTempFilename creates a temporary filename AND creates the temporary file in either the specified folder
or in the temporary folder - same as returned by GetTempFolder.
Example:
ITC ITCoreClass
Fn CString(2049)
Pref CString(4)
Code
Fn = ITC.GetTempFileName()
Message('Temp filename: ' & Fn)
This will return a filename in the temp folder and at this point this file already exists. In this
case the function will return a unique filename that is usually build up with hexadecimal characters
and could look something like C:\WINDOWS\TEMP\35.tmp
Note that the GetTempFileName() always returns the ShortPath() of the path.
Example:
ITC ITCoreClass
Fn CString(2049)
Pref CString(4)
Code
Pref = 'ITCTEST'
Fn = ITC.GetTempFilename(Path(),Pref)
Message('Temp filename: ' & Fn)
In this case the function will return (and create) a file called something like ITC2F.tmp in the
currently active folder. The Pref variable is an optional prefix that you can specify but
note that only the first 3 characters of the prefix are used.
This is a limitation of the API call, not of the GetTempFilename method! This would return something
like C:\Clarion\Apps\C63\Products\UTILIT~1\Demos\CORECL~1\ITC36.tmp
Example:
ITC ITCoreClass
Fn CString(2049)
Code
Fn = ITC.GetTempFilename(Path(),Pref)
Remove(Fn)
Fn = ITC.GetFilepart(Fn,FNS_FileName)
Fn = '"' & LongPath() & '\ITCTEST' & Fn & '"'
Message('Temp filename: ' & Fn)
Of course there is nothing preventing you from being creative and creating a longer prefix to your
temporary filename! The above code creates the temp filename, then removes the file that it created.
It then retrieves the filename only (filename + extension) from the full pathname returned by GetTempFilename
and adds "ITCTEST" in front of the filename as it combines it with the Path(). This would return something
like "C:\Clarion\Apps\C63\Products\UtilityClass\Demos\CoreClass\ITCTEST34.tmp" Notice that in this case
we use LongPath() instead of Path() to get the long path to the file. Also notice that we remove the file
created by the GetTempFilename right after we call it before we start manipulating the filename.
9 Files Available for Download for Icetips Utilities
| File Date |
Description |
Size |
File |
| 2010-06-06 |
Icetips Utilities 1.1.2387 |
11852,032 |
ITUtilities_Install_1.1.2387.exe |
| |
Build 1.1.2387 Compatible with Clarion 6.0-6.3 and Clarion 7.0 - 7.2
|
| 2010-03-15 |
Icetips Utilities 1.1.2374 |
11499,904 |
ITUtilities_Install_1.1.2374.exe |
| |
Build 1.1.2374 Compatible with Clarion 6.0-6.3 and Clarion 7.x
|
| 2010-02-26 |
Icetips Utilities 1.1.2367 BETA |
11,110,656 |
ITUtilities_Install_1.1.2367.exe |
| |
Build 1.1.2367 BETA Compatible with Clarion 6.0-6.3 and Clarion 7.x
|
| 2010-01-27 |
Icetips Utilities 1.1.2359 |
10,188,296 |
ITUtilities_Install_1.1.2359.exe |
| |
Build 1.1.2359 Compatible with Clarion 6.0-6.3 and Clarion 7.x
|
| 2010-01-26 |
Icetips Utilities 1.1.2356 |
10,189,568 |
ITUtilities_Install_1.1.2356.exe |
| |
Build 1.1.2356 Compatible with Clarion 6.0-6.3 and Clarion 7.x
|
| 2009-04-20 |
Icetips Utilities 1.1.2352 |
8,526,192 |
ITUtilities_Install_1.1.2352.exe |
| |
Build 1.1.2352 Compatible with Clarion 6.0-6.3 and Clarion 7
|
| 2009-04-15 |
Icetips Utilities 1.1.2351 |
7,245,608 |
ITUtilities_Install_1.1.2351.exe |
| |
Build 1.1.2351 Compatible with Clarion 6.0-6.3 and Clarion 7
|
| 2008-09-02 |
Icetips Utilities Documentation (PDF) |
1,627,355 |
ITUtility.pdf |
| |
PDF Documentation (189 pages) for version 1.1.2319
|
| 2007-08-14 |
Page of Pages demo |
742,438 |
PageOfPages.zip |
| |
This small demo, using the invoice.dct from the Clarion 6.3 examples, demonstrates basic use of the Page of Pages class in the Icetips Utilities. The zip includes app, dct, tps and other necessary files. It also includes a locally compiled exe.
|
This page was last modified on June 01, 2009.
|
|
|
|