Handling files is a necessary task in any application. Visual FoxPro provides a great number of functions to handle files, most of which are data related. But sometimes it would be nice to get a little more technical information about those files, and that's exactly what these classes do.
Class |
_fileversion |
Base class |
Custom |
Class library |
_utility.vcx |
Parent class |
_custom |
Sample |
...\Samples\Vfp98\Solution\WinAPI\getver.scx |
Dependencies |
_base.vcx, _utility.h |
The File Version object allows you to retrieve detailed information about EXE and DLL files. This information can be interesting at design time, and it is often important during runtime to make sure the proper file versions are present.
The detailed file information is stored in the aVersion() property array. To populate this array, you first have to set the cFileName property and call the GetVersion() method:
oFileVersion = NewObject("_fileversion","_utility.vcx")
oFileVersion.cFileName = Home() + "VFP6.EXE"
oFileVersion.GetVersion()
The created array is one-dimensional and has 15 rows. Table 3 explains the meaning of each item. The items can be displayed using the DisplayVersion() method, which displays a message box with all the information. The user interface cannot be changed unless you overwrite the entire method.
Table 3.
The contents of the aVersion() array.
Row |
Description |
1 |
Comments |
2 |
Company name |
3 |
File description |
4 |
File version |
5 |
Internal name |
6 |
Legal copyright |
7 |
Legal trademarks |
8 |
Original file name |
9 |
Private build |
10 |
Product name |
11 |
Product version |
12 |
Special build |
13 |
OLE self registration (contains "OLESelfRegister" if the file supports self-registration; otherwise contains the empty string) |
14 |
Language (derived from the translation code) |
15 |
Hexadecimal translation code |
Class |
_filer |
Base class |
Custom |
Class library |
_utility.vcx |
Parent class |
_custom |
Sample |
...\Samples\Vfp98\Tools\Filer\Filer.scx |
Dependencies |
_base.vcx, _utility.h, filer.dll |
The Find Files/Text foundation class is a wrapper for the Filer.dll COM object. You can use this class to search for files that have a certain name (wildcards such as * and ? are allowed) and/or files that contain a certain text string.
Using this class is straightforward. A number of properties can be used to specify search parameters, such as the text to be searched, the files you want to search, the path, and so forth. Here is an example:
set classlib to _utility.vcx
oFiler = NewObject("_filer","_utility.vcx")
oFiler.cFileExpression = "*.XML"
oFiler.cSearchPath = "C:\My Documents\"
oFiler.cSearchText = "Some Text"
oFiler.lIgnoreCase = .T.
oFiler.lSubFolder = .T.
nFilesFound = oFiler.Find()
This example searches all the XML files in "C:\My Documents\" (and all subdirectories) that contain the string "Some Text". The Find() method initiates the actual search and returns the number of files that were found. Then it starts to get a little trickier, especially because the following isn't documented in the Visual FoxPro Foundation Class documentation.
The Find() method populates a collection of files that can be referenced through the oFiles property. This collection has a property called Count that we can use to query the number of files (in case we missed the return value):
nFilesFound = oFiler.oFiles.Count
The oFiles reference doesn't have any other properties, but there is an Item() collection that can be used to access each individual item. Each item has more properties that describe each file.
FOR nCounter = 1 TO oFiler.oFiles.Count
? oFiler.oFiles.Item(nCounter).Name
ENDFOR
All properties and methods of the objects in the Item collection are described in Tables 4 and 5.
Table 4
. The properties of the objects in the Item collection.
Property |
Type |
Description |
Example |
AlternateName |
C |
The short name of the file if the real name exceeds the 8.3 naming convention. |
? oFiles.Item(1).AlternateName |
Attr |
N |
The Windows file attributes for the file in a numeric format.
More than one value can be set at a time. If the value is 6 (for instance), we have a hidden system file.
|
? oFiles.Item(1).Attr |
DateTime |
N |
The numeric time stamp assigned by Windows when the file is created. The integer portion of the time stamp represents the number of days since 12/30/1899, and the remainder is the fractional remainder of the day from which you can determine the time when the file was created. |
? oFiles.Item(1).DateTime |
LastAccessTime |
N |
The time stamp assigned by Windows when the file was accessed the last time. |
? oFiles.Item(1).LastAccessTime |
LastWriteTime |
N |
The time stamp assigned by Windows when the file was modified the last time. |
? oFiles.Item(1).LastWriteTime |
Name |
C |
The full file name. |
? oFiles.Item(1).Name |
Path |
C |
The full path to the file. |
? oFiles.Item(1).Path |
Size |
N |
File size in bytes. |
? oFiles.Item(1).Size |
SizeHigh |
N |
The high 4 bytes of the file size if the file is greater than 4 gigabytes. |
? oFiles.Item(1).SizeHigh |
Table 5
. The methods of the object in the Item collection.
Name |
Description |
Example |
Edit |
Uses the Visual FoxPro editor to modify the file. |
oFiles.Item(1).Edit() |
Delete |
Deletes the file from disk. The file is not placed in the Recycle Bin! |
oFiles.Item(1).Delete() |
Class |
_typelib |
Base class |
Container |
Class library |
_utility.vcx |
Parent class |
_container |
Sample |
...\Samples\Vfp98\Solution\Forms\typelib.scx |
Dependencies |
_base.vcx, _utility.h, FoxTLib ActiveX control |
The Type Library foundation class is a wrapper for the Visual FoxPro Foxtlib ActiveX control that ships with Visual FoxPro. It can be used to handle and use type library information in your applications. Type libraries host information about COM controls and servers. The Type Library foundation class is a container that hosts this ActiveX control. You can drop this container on another container such as a form. You cannot instantiate the Type Library class by itself.
To load a type library, you first specify its name and then call the GetTypeLib() method, like so:
oTL.TypeLibName = FullPath("wbserver.tlb")
oTL.GetTypeLib()
This code loads the type library, retrieves the number of type infos, stores it in the TypeInfoCount property, and finally loads some basic information in the aTypeLibDocs array. This array always has three elements: they hold information about the name, the document string, and the help file of the selected member. In the beginning, this information is specific to the entire type library; it is not member-specific.
Now that we have this information, we can explore the Type Library class further. The GetTypeInfo() method collects type information of a certain type info key. We already know how many type info keys we have (TypeInfoCount). When we retrieve the type information for one of those keys, the arrays aTypeInfoDocs and aTypeAttr are populated. The return value of GetTypeInfo() is 0 if everything went okay, or -1 if an error occurred. The aTypeAttr array is a one-dimensional array that holds information about a certain type index. Table 6 describes the meaning of each element.
Table 6
. The rows in the aTypeAttr array.
Item |
Description |
Item |
Description |
|
1 |
GUID (Unique ID that identifies the server) |
9 |
Number of functions |
|
2 |
LocaleID |
10 |
Number of variables/members |
|
3 |
Reserved |
11 |
Number of implemented interfaces |
|
4 |
Constructor ID |
12 |
Size of type's virtual function table |
|
5 |
Destructor ID |
13 |
Byte alignment of an instance of this type |
|
6 |
Reserved |
14 |
Flags |
|
7 |
Instance size |
15 |
Major version number |
|
8 |
Type Kind |
16 |
Minor version number |
Using the GetFuncDesc() method, we can also retrieve information about a specific function that is documented in the type library. This method requires passing the function index as the first parameter. It populates the aTypeFuncDesc, aTypeFuncParms, aTypeFuncNames and aTypeFuncDocs arrays as well as the FuncNamesCount property. The aTypeFuncDesc array contains information about the function (see Table 7), while the aTypeFuncParms array stores information about the function parameters.
Table 7
. The rows in the aTypeFuncDesc array.
Item |
Description |
1 |
ID |
2 |
Function kind. Specifies whether the function is virtual, static, or dispatch only. Possible values: FUNC_PUREVIRTUAL = The function is accessed through the virtual function table and takes an implicit "this" pointer. FUNC_VIRTUAL = The function is accessed the same as PUREVIRTUAL, except the function has an implementation. FUNC_NONVIRTUAL = The function is accessed by static address and takes an implicit "this" pointer. FUNC_STATIC = The function is accessed by static address and does not take an implicit "this" pointer. FUNC_DISPATCH = The function can be accessed only through IDispatch. |
3 |
Invoke kind. Specifies whether this is a property function, and if so, what kind. Possible invocation kinds: INVOKE_FUNC = The member is called using normal function invocation syntax. INVOKE_PROPERTYGET = The function is invoked using normal property access syntax. INVOKE_PROPERTYPUT = The function is invoked using property value assignment syntax. INVOKE_PROPERTYPUTREF = The function is invoked using property reference assignment syntax. |
4 |
Specifies the function's calling convention. |
5 |
Total number of parameters. |
6 |
Number of optional parameters. |
7 |
For FUNC_VIRTUAL, specifies the offset in the virtual table. |
8 |
Count of permitted Scodes. |
9 |
Flags. Possible flags: FUNCFLAG_FRESTRICTED (1) = The function should not be accessible from macro languages. This flag is intended for system-level functions or functions that type browsers should not display. FUNCFLAG_FSOURCE (0x02) = The function returns an object that is a source of events. FUNCFLAG_FBINDABLE (0x04) = The function supports data binding. FUNCFLAG_FDISPLAYBIND (0x10) = The function is displayed to the user as bindable; that is, the bindable flag must also be set. FUNCFLAG_FDEFAULTBIND (0x20) = The function that best represents the object. Only one function in a type info can have this attribute. FUNCFLAG_FHIDDEN (0x40) = The function should not be displayed to the user, though it exists and is bindable. |
The aTypeFuncNames array holds information about the function names. The aTypeFuncDocs array is a one-dimensional array with three elements and it's identical to the aTypeLibDocs array.
The Type Library object can also export the type library information to a text file using the ExportTypeLib() method. This method takes two parameters: the file name and (optional) whether or not the file should be displayed right away (.T.).