Dynamic File Driver Reference
Dynamic File Driver Reference
This publication is protected by copyright and all rights are reserved by SoftVelocity Incorporated. It may
not, in whole or part, be copied, photocopied, reproduced, translated, or reduced to any electronic
medium or machine-readable form without prior consent, in writing, from SoftVelocity Incorporated.
This publication supports Clarion. It is possible that it may contain technical or typographical errors.
SoftVelocity Incorporated provides this publication “as is,” without warranty of any kind, either expressed
or implied.
SoftVelocity Incorporated
2335 East Atlantic Blvd. Suite 410
Pompano Beach, Florida 33062
(954) 785-4555
[Link]
Trademark Acknowledgements:
Contents:
Dynamic File Driver (DFD) 5
Overview ............................................................................................................................. 5
Setup ................................................................................................................................... 5
Working with Dynamic files - conceptual flow ..................................................................... 6
Getting started..................................................................................................................... 7
Dynamic File Interface – Overview 9
Creating and Destroying a Dynamic File ............................................................................ 9
Defining a file using PROP:SQL ......................................................................................... 9
Defining a File Manually.................................................................................................... 11
Interface Specifics 13
Using Dynamic File Support ............................................................................................. 13
Language Support............................................................................................................. 13
FIXFORMAT (fix a dynamic file)................................................................................. 13
UNFIXFORMAT (unfix a dynamic file) ....................................................................... 13
File Structure Properties ................................................................................................... 14
Defining the record structure – general rules.................................................................... 16
Field (Column) Properties ................................................................................................. 16
Defining Keys .................................................................................................................... 17
Defining Memos and Blobs ............................................................................................... 18
DFD Templates 19
Dynamic File Driver Global Extension .............................................................................. 20
“Cache Files on this thread” extension template .............................................................. 23
Requirements ............................................................................................................. 23
Shipping Examples 25
DynFile Class 27
Overview ........................................................................................................................... 27
DynFile Class Source Files............................................................................................... 27
DynFile Properties............................................................................................................. 27
DynFile Methods ............................................................................................................... 28
AddField (add field to a Dynamic File Structure)........................................................ 28
AddFieldToKey (add field to dynamic file Key definition) ........................................... 29
AddKey (add key to a Dynamic File Structure) .......................................................... 30
AddMemo (add memo to a Dynamic File Structure) .................................................. 31
CacheFile(load table into in-memory dynamic file) .................................................... 32
CreateFromFile (build Dynamic File Structure from existing file)............................... 33
CreateFromSQL(create structure from SQL result set).............................................. 34
CreateKeyComponents (create key elements of a dynamic file key)......................... 35
CreateStruct (build a dynamic file structure) .............................................................. 36
FillFrom (copy data to a Dynamic File Structure) ....................................................... 37
FillTo (copy dynamic file contents to table) ................................................................ 39
GetCreate (get value of Create property)................................................................... 42
GetDriver (get value of Driver property) .................................................................... 42
GetEncrypt (get value of Encrypt property) ................................................................ 42
GetField (get field contents) ....................................................................................... 43
GetFieldName (get label name of field)...................................................................... 44
GetFieldValue (move field value to a reference) ........................................................ 45
GetFileRef (get reference to a dynamic file)............................................................... 46
GetKeyRef (get reference to a dynamic file’s key) ..................................................... 47
GetName (get value of Name property) ..................................................................... 48
GetOEM (get value of OEM property) ........................................................................ 48
GetOwner (get value of Owner property) ................................................................... 48
GetPrefix (get value of Prefix property) ...................................................................... 49
4 Dynamic File Driver Reference
Here are just a few of the things that can be accomplished using the DFD:
• Dynamically create a FILE structure to match the result set from any SQL SELECT command or
from a Stored Procedure.
• Dynamically create In-Memory driver FILE structures for use as "cached recordsets" from any
data source (ISAM or SQL).
• Create and process tables that are not defined in the application’s dictionary.
Setup
Setup is easy! Just register [Link] in the Template Registry. You do not need to register the
Dynamic File Driver (or DynaDriver) in the Database Drivers Registry.
6 Dynamic File Driver Reference
AFile &FILE
AKey &KEY
FIXFORMAT(AFile)
CREATE (AFile)
OPEN(AFile)
! do cleanup processing
DISPOSE (AFile)
Dynamic File Driver Reference 7
Getting started
The Dynamic File Driver has powerful functionality that helps you to create file structures at runtime. To
become familiar with the syntax for defining dynamic file structures read the Interface Overview section.
The DynFile class was designed to simplify the task of creating dynamic file structures. The class
encapsulates all of the functions needed to define dynamic files and its methods can be used to simplify
and reduce the code needed to create a dynamic file to a few lines. The class is documented in the
DynFile Class section.
The DynaFile template may provide all the functionality that you need. Please refer to the DFD
Templates section.
Some of the examples found in ..\Examples\DFD\<example> are documented in this manual in the
Annotated Examples section.
We suggest that you skim through this manual and then run some of the DFD examples. Examine the
code used in the examples and then revisit this manual when necessary.
8 Dynamic File Driver Reference
Dynamic File Driver Reference 9
For Example:
AFile &FILE
CODE
AFile &= NEW (FILE)
…..
DISPOSE (AFile)
Example:
AFile &FILE
CODE
AFile &= NEW (FILE)
AFile {PROP:Driver} = ‘MSSQL’
AFile {PROP:Owner} = ‘Connection String’
AFile {PROP:SQL} = ‘SELECT * FROM MyTable’
FIXFORMAT (AFile)
UNFIXFORMAT (AFile)
AFile {PROP:SQL} = ‘CALL MyStoredProcedure(3)’
FIXFORMAT (AFile) !Now the file will match the columns
!returned by the stored procedure
DISPOSE (AFile)
10 Dynamic File Driver Reference
It is valid to change PROP:Driver after using PROP:SQL. You can use this to create, for
example, an In-Memory file that can be used to hold the results of an SQL statement.
Example:
IMDDFile &FILE
ODBCFile &FILE
bGroup &GROUP
oGroup &GROUP
CODE
IMDDFile &= NEW(FILE)
IMDDFile {PROP:Driver} = 'ODBC'
IMDDFile {PROP:Owner} = ‘MyDataSource’
IMDDFile {PROP:TextAsString} = 400
IMDDFile {PROP:ImageAsString} = 400
IMDDFile {PROP:SQL} = ‘SELECT * FROM MyTable’
IMDDFile {PROP:Driver} = 'In-Memory'
IMDDFile {PROP:Create} = TRUE
IMDDFile {PROP:Name} = ‘Results’
FIXFORMAT(IMDDFile)
bGroup &= IMDDFile{PROP:Record}
CREATE(IMDDFile)
OPEN(IMDDFile)
LOOP
NEXT(ODBCFile)
IF ERRORCODE() THEN BREAK.
bGroup = oGroup
ADD(IMDDFile)
END
! do processing
CLOSE(IMDDFile)
CLOSE(ODBCFile)
DESTROY(IMDDFile)
DESTROY(ODBCFile)
Dynamic File Driver Reference 11
Example:
AFile &FILE
AKey &KEY
CODE
AFile &= NEW (FILE)
AFile{PROP:Driver} = ‘TopSpeed’
AFile{PROP:Create} = TRUE
AFile{PROP:Name, 1} = ‘Field1’
AFile{PROP:Type} = ‘LONG’
AFile{PROP:Dim} = 3
AKey &= AFile {PROP:Key, 1}
AKey{PROP:Type} = ‘KEY’
AKey{PROP:Primary} = TRUE
AKey{PROP:Field} = 1
FIXFORMAT(AFile)
CREATE(AFile)
DISPOSE(AFile)
12 Dynamic File Driver Reference
Dynamic File Driver Reference 13
Interface Specifics
Using Dynamic File Support
Any program that uses dynamic file system must link in C60DFX%L%.LIB.
Language Support
The Dynamic File Driver provides the following language statements:
If Error code 47 is posted, the FILEERRORCODE function can be used to return extended information.
See the ErrorCode 47 Extended information topic for more information.
If Error code 47 is posted, the FILEERRORCODE statement can be used to return extended information.
See the ErrorCode 47 Extended information topic for more information.
14 Dynamic File Driver Reference
You cannot set PROP:Thread. Dynamically created files are not threaded. If you want to
“thread” a dynamically created file, then you need to add the THREAD attribute on the file
reference and create the file definition on each thread, or cache the data into a THREADed In-
Memory table.
Value = File{PROP:Fields}
Returns the field ID for the maximum field defined so far.
Value = File{PROP:Keys}
Returns the key ID for the maximum key defined so far.
Value = File{PROP:Blobs}
Returns the blob ID for the maximum blob defined so far.
Value = File{PROP:Memos}
Returns the memo ID for the maximum memo defined so far.
Once PROP:Driver or PROP:FileDriver has been set, you can also read the following file driver
properties:
Value = File{PROP:SQLDriver}
PROP:SQLDriver returns TRUE if the file drive is an SQL based file driver and therefore supports
the PROP:SQL statements and other SQL only features.
Dynamic File Driver Reference 15
Value = File{PROP:SupportsOp}
PROP:SupportsOp is an array property that returns TRUE if the driver supports the file driver
function. This list of operation codes is defined in [Link]
Value = File{PROP:SupportsType}
PROP:SupportsType is an array property that returns TRUE if the driver supports the data type.
This list of operation data types is defined in [Link]
Value = File{PROP:DriverLogsoutAlias}
PROP:DriverLogsoutAlias returns true if the file driver logs out a file and its aliases when you
logout the file. The TopSpeed driver returns true for this op. All other drivers return false.
16 Dynamic File Driver Reference
2. You do not have to create fields in any specific order. It is valid to define field five, then field one.
However, FIXFORMAT will return an error if there are any gaps in the field numbering.
3. Before FIXFORMAT is called File{PROP:Fields} will return the maximum field number currently
defined.
4. When defining a file structure using property syntax many properties take values 0 or 1. You can
also use an empty string instead of 0.
5. If FIXFORMAT has not been called on a file, all of properties return FALSE and ERRORCODE is
set to 80.
File{PROP:Label, n} = string
File{PROP:Name, n} = string
If PROP:Name is specified for a field, and PROP:Label is not specified, then the system will
create a label for the field based on the name.
File{PROP:Type, n} = string
The string assigned to this property must be the name of a standard Clarion data type. The case
of the string does not matter.
If you specify an invalid string ERRORCODE will be set to TypeDescErr (75).
File{PROP:Places, n} = number
Only valid if PROP:Type is DECIMAL or PDECIMAL
If number < 0, ERRORCODE() will be set to InvalidFileErr (47)
File{PROP:Size, n} = number
Only valid if PROP:Type is DECIMAL, PDECIMAL, STRING, CSTRING or PSTRING.
If number < 0 or number > 4,190,208, ERRORCODE() will be set to InvalidFileErr(47).
If you specify an even number for the size of a PDECIMAL or DECIMAL field, it will be converted
to the next largest number. This is due to the way these fields are stored in memory.
File{PROP:Field, n} = ''
Use this form to delete a field from the dynamic file definition.
Dynamic File Driver Reference 17
Defining Keys
To define a key, use File{PROP:Key, n} to obtain a reference to a key and then set the attributes
of the key using that key reference.
You are limited to 255 keys in a file definition. Attempting to get a key reference for a key greater
than 255 will return a NULL reference.
You are limited to 255 components in a key. Attempting to set a property of a component outside
this range will return an error of NoDrvFunc(80)
Key{PROP:Label} = string
Key{PROP:Name} = string
If PROP:Name is specified for a key, and PROP:Label is not specified, then the system will
create a label for the key based on the name.
Key{PROP:Dup} = 0 | 1
If not specified, then 0 is assumed
Key{PROP:Primary} = 0 | 1
If not specified, then 0 is assumed
Key{PROP:NoCase} = 0 | 1
If not specified, then 0 is assumed
Key{PROP:Opt} = 0 | 1
If not specified, then 0 is assumed
Key{PROP:Field, n} = number
If number <= 0, ERRORCODE() will be set to InvalidFileErr(47)
Key{PROP:Ascending, n} = 0 | 1
If not specified, then 1 is assumed
Value = Key{PROP:Fields}
Returns the component ID for the maximum component defined so far.
18 Dynamic File Driver Reference
You are limited to 255 memos and blobs in a file structure. Attempting to set a property of a
memo or a blob outside this range will return an error of NoDrvFunc(80)
File{PROP:Binary, -n} = 0 | 1
If not specified, then 0 is assumed.
File{PROP:Memo, n} = ‘’
or
File{PROP:Memo, -n} = ‘’
Dynamic File Driver Reference 19
DFD Templates
The Dynamic File Driver library includes a basic support template set that helps you to easily integrate
dynamic file support into your existing applications.
To register the template, select the Template Registry menu item from the Clarion IDE Setup main
menu. You need to register [Link]:
For purposes of this template documentation, the term “DynaDriver” refers to a class library
used for Dynamic File Driver support. The class properties and methods are discussed in
more detail in this document.
20 Dynamic File Driver Reference
1. By including the global extension into your application, the required libraries and the DynFile
classes (containing a robust set of methods written to help you easily manage your dynamic files)
are included into your application.
2. The “Load File” option, where a dictionary table used in your application can load values from any
alternate data source. For example, an In-Memory table at program start up can read values
from a TopSpeed file or SQL data source. At program shutdown, the modified values can
optionally be written back to the alternate data source.
Check this box to automatically make the DynFile class available in your applications. The complete
set of available methods is documented in this manual.
Load Files
The Load Files option allows the Dynamic Driver to be used to easily load one file from another data
source. The file to load should usually be an In-Memory table, but you are not limited to this particular
driver. The template creates two global procedures, LoadDynamicFiles and SaveDynamicFiles that
handles all of the logic and housekeeping needed to do this.
In the Load Files tab, a list box is displayed that displays the tables that are created by the Dynamic
File Driver. To add, or modify their existing behavior, press the appropriate update buttons.
If you are linking in local mode, you must override this method and include the modified form
of the SetDriver method. See the documentation for SetDriver for more information.
Dynamic File Driver Reference 21
To override the SetDriver method, simply use the following global embeds:
In the example shown above, Employee is the label of a file that contains the matching driver type of
the dynamic file that will be created. ThisDyn is the default template name of the DynaFile class
object.
In the Load Files on StartUp dialog, the following prompts are displayed:
File
Press the ellipsis button, and select the dictionary table that will be created and populated by the
Dynamic File Driver using the DynFile class methods. In most cases, this should be an In-Memory
table, but you are not limited to this.
If the file selected is an In-Memory table, you need to select the driver type (From Driver), full
pathname, and owner information (if applicable) of the alternate data source. If the file selected is not
an In-Memory table, it is assumed that this file will be the alternate data source. The remaining
prompts are disabled, and the dynamic file created will be an In-Memory table that matches the File
definition.
From Driver
Select the driver type from the alternate data source that will be used to populate the dictionary file. If
the full pathname and owner is not specified, the alternate data source should default to the first eight
letters of the dictionary table, with the appropriate extension as identified by the driver.
For example, if your File named is “Department”, and the driver type is TOPSPEED, the file that will
be loaded will be “[Link]”
Full Pathname
Enter the actual name and path of the alternate data source, if needed.
For Example:
C:\DATA\[Link]
Owner
If the alternate data source is an encrypted ISAM type, enter the valid password information here. If
the alternate data source is an SQL source, enter the valid connection strong information here.
Example:
Myserver,northwind,sa,mypassword
Check this box to automatically save the contents of the dynamic file to the original data source.
If you want to save (all the tables) while your program is still running, then use:
SaveDynamicFiles()
Even if you have not ticked the Save File on closing option, you can still force a single table to write
back to the disk using the SaveFile method.
Dynamic File Driver Reference 23
Use this template when a dynamic file is used on a single thread, and the file to process is large. Its use
will substantially improve the initialization and loading of the dynamic file.
Requirements
This template (as with the global extension Dynamic File Driver Global Extension) requires that you have
the In-Memory Database Driver (IMDD) installed.
When you press the Insert button to add a table to cache, the following option is available:
File
In the Cache Files on this Thread dialog, press the ellipsis button to select any valid ISAM or SQL file that
will be automatically cached to an In-Memory dynamic file.
24 Dynamic File Driver Reference
Dynamic File Driver Reference 25
Shipping Examples
There are many examples that are shipped with the Dynamic File Driver. Each one is designed to
illustrate a different usage or configuration of the dynamic file driver. Clarion and ABC templates are both
showcased. Some examples are hand coded. They are all located by default in the Clarion Root
Examples folder, in a default DFD subfolder:
CACHE
If you were to examine your application’s data dictionary, you would most likely be able to identify a
number of tables that are infrequently changed. This might be a department list, ZIP codes, country
names, etc. If these tables are set as In-Memory files you will gain quite a bit of performance.
This core application demonstrates loading a TopSpeed table, which not defined in the dictionary, into an
In-Memory table defined in the dictionary, using the DynFile class methods via the template support.
There is also a similar application ([Link]) in this folder that demonstrates the necessary
modifications needed for using a local link with your DFD applications.
Cache1Thread
This application demonstrates the use of the Cache Files on this thread procedure extension, and
demonstrates creating a procedural dynamic file used with an ISAM or SQL source. Refer to the
ReportDepartmentsFast procedure for more information.
CacheInMemABC
Same as the core CACHE application, but does not use a Full pathname in the Global extension, and
saves any changes made to the dynamic file to the TopSpeed data source on closing.
CacheInMemFromMsSql
Demonstrates caching an SQL table to an in-memory dynamic file.
NOTE:
You will need to create a test database on your MSSQL server that matches the In-memory definition
defined in the dictionary.
CacheMsSqlFromMsSql
This application demonstrates using a dynamic file to read data from an SQL data source, and storing it in
a dynamic MSSQL table created by the templates. You will need to set the GLO:Owner string to attach to
your MSSQL server.
This application was designed to show you that the In-memory driver does not have to be used with your
dynamic file implementation.
CacheTPSABC
This application demonstrates an alternate template configuration from the core CACHE application. By
designating a TopSpeed file as the global file to load on startup, the template implicitly creates an In-
Memory dynamic table that does not have to be defined in the data dictionary. The core example had an
In-Memory table defined in the dictionary, but referred to the TopSpeed table as an external source.
Both applications perform the same function, but we are showing the flexibility of dynamic file
configuration.
Memos
This application demonstrates using a dynamic file with tables that include a MEMO data type.
FillListBox
This example uses the DynFile class library, and demonstrates creating dynamic files “on the fly” from
both SQL and ISAM sources. It is essential that you examine this program if you plan to hand code any
dynamic file implementations.
ReadFileStruct
This hand-coded example shows the dynamic file driver in a simple application, to dump the structure of a
file to a dynamic ASCII table. This example is a good start to learning how to use the syntax of the
dynamic file driver implementation.
Dynamic File Driver Reference 27
DynFile Class
This section documents the DynFile Class that is used to integrate a rich language and template support
layer used with the Dynamic File Driver.
Overview
The Dynamic File Driver has powerful logic built into the runtime library that helps you to create any file
format on the fly. The DynFile class was designed to simplify the task of creating dynamic file structures.
DynFile Properties
All of the DynFile properties are PRIVATE, and cannot be referenced directly by the programmer.
This section only documents these properties as they are referenced in the DynFile methods
documentation.
sDriver
A STRING that identifies the contents of the DRIVER attribute used in the dynamic file.
sFileDriver
A reference to a FILE that identifies the DRIVER type used in the dynamic file.
bCreate
A BYTE that identifies if the CREATE attribute is applied to the dynamic file
bReclaim
A BYTE that identifies if the RECLAIM attribute is applied to the dynamic file
bEncrypt
A BYTE that identifies if the ENCRYPT attribute is applied to the dynamic file
bOEM
A BYTE that identifies if the OEM attribute is applied to the dynamic file
sOwner
A STRING that identifies the contents of the OWNER attribute used in the dynamic file.
sName
A STRING that identifies the contents of the NAME attribute used in the dynamic file.
sPrefix
A STRING that identifies the contents of the PRE attribute used in the dynamic file.
28 Dynamic File Driver Reference
DynFile Methods
AddField (add field to a Dynamic File Structure)
AddField(fieldgroup)
fieldgroup A GROUP that uses the TFieldGrp DynFile TYPEd group structure.
AddField is a virtual method that allows you to add a field and its associated properties to a dynamic file
structure. The fieldgroup must match the TYPEd TFieldGrp defined in the DynFile class:
TFieldGrp GROUP, TYPE
FieldNbr LONG
Label STRING(DynDrvSize:Label)
Name STRING(DynDrvSize:Name)
Type STRING(DynDrvSize:Type)
Over LONG
Dim LONG
Size ULONG
Places ULONG
Fields LONG !represents the number of fields the group will contain
END
Implementation: The AddField method should be applied any time prior to the FixFormat method
Example:
MyFieldGrp group(TFieldGrp).
CODE
! Add some fields to record structure
[Link] = 1
[Link] = 'SysID'
[Link] = 'LONG'
[Link](MyFieldGrp)
[Link] = 2
[Link] = 'FirstName'
[Link] = 'STRING'
[Link] = 50
[Link](MyFieldGrp)
[Link] = 3
[Link] = 'LastName'
[Link] = 'STRING'
[Link] = 50
[Link](MyFieldGrp)
Dynamic File Driver Reference 29
keyname A STRING constant, variable, or expression that identifies the label of the key
fieldname A STRING constant, variable, or expression that identifies the label of the field
sequence A BYTE value that identifies an ascending (1) or descending (0) sequence.
rank A BYTE value that identifies the rank, or order, that the fieldname is positioned in the
keyname. A value of 1 indicates that it is the highest ranking (first) key component.
Implementation: The AddFieldToKey method should be applied any time prior to the FixFormat method
Example:
MyDynFile class(cDynFile)
End
CODE
[Link]('kSysID', 'SysID', true, 1)
!Parameters are KeyName, FieldName, Sequence, Component rank in the key
30 Dynamic File Driver Reference
keygroup A GROUP that uses the TKeyGrp DynFile TYPEd group structure.
AddKey is a virtual method that allows you to add a key and any associated properties to a dynamic file
structure. The keygroup must match the TYPEd TKeyGrp defined in the DynFile class:
TKeyGrp GROUP, TYPE
KeyNbr LONG
Label STRING(DynDrvSize:Label)
Name STRING(DynDrvSize:Name)
Type STRING(1) ! K = Key, I = Index
Dup BYTE ! False = no duplicate, True = duplicates allowed
Primary BYTE ! False = not primary, True = key is primary key
NoCase BYTE ! False = case sensitive, True = No case
Opt BYTE ! False = not optional, True = optional
END
Implementation: The AddKey method should be applied any time prior to the FixFormat method
Example:
CODE
memogroup A GROUP that uses the TMemoGrp DynFile TYPEd group structure.
AddMemo is a virtual method that allows you to add a MEMO or BLOB data type and its associated
properties to a dynamic file structure. The memogroup must match the TYPEd TMemoGrp defined in the
DynFile class:
TMemoGrp GROUP, TYPE
MemoNbr LONG ! Must be negative, first memo = -1, second memo = -2 etc...
Label STRING(DynDrvSize:Label)
Name STRING(DynDrvSize:Name)
Type STRING(1) ! M = Memo, B = Blob
Binary BYTE ! True = Binary contents, False = Text
size ULONG
END
Implementation: The AddMemo method should be applied any time prior to the FixFormat method
Example:
CODE
[Link] = -1
[Link] = 'NOTES'
[Link] = 'M' ! M is for MEMO
[Link] = 4096 ! memo is 4k in size
[Link](MyMemoGrp)
[Link] = -2
[Link] = 'Photo'
[Link] = 'B' ! B is for blob
[Link] = TRUE
[Link](MyMemoGrp)
32 Dynamic File Driver Reference
filelabel The label of a valid FILE that identifies the data source.
drivername A string constant, variable or expression that identifies the name of the file driver that
applies to the data source.
namestring A string constant, variable or expression that contains the operating system device name
for the structure identified by the filelabel to use with the data source.
ownerstring A string constant, variable or expression that contains file encryption password, or SQL
connection string for the data source.
CacheFile is a virtual method that allows a single-line call that changes an ISAM or SQL table to an In-
Memory table, and loads it from the source. CacheFile is used to cache a table on a single thread.
Implementation: The CacheFile method can be applied to any procedure prior to processing the file.
NOTE: YOU MUST HAVE THE IN-MEMORY DRIVER to use this method. There is a
template extension available to help you implement this easily in any procedure. See the
DFD Templates section in this PDF for more information.
Example:
ThisDyn Class(DynFile)
End
DynWaitWindow WINDOW('Please Wait'),AT(,,116,18),FONT('MS Sans Serif',8,,FONT:regular),|
CENTER,GRAY,DOUBLE
STRING('Please Wait: Caching Tables.'),AT(0,3,116,12),USE(?DynWaitString),TRN,CENTER
END
CODE
c = clock()
[Link]('ReportDepartmentsFast')
[Link] = GlobalRequest ! Store the incoming request
ReturnValue = [Link]()
IF ReturnValue THEN RETURN ReturnValue.
[Link] = ?Progress:Thermometer
[Link] &= VCRRequest
[Link] &= GlobalErrors !Set this windows ErrorManager to global ErrorManager
CLEAR(GlobalRequest) ! Clear GlobalRequest after storing locally
CLEAR(GlobalResponse)
OPEN(DynWaitWindow)
DISPLAY()
[Link](Employee,'TOPSPEED',,)
[Link](LinkEmpDept,'TOPSPEED',,)
CLOSE(DynWaitWindow)
Relate:[Link]()
Dynamic File Driver Reference 33
CreateFromFile is a virtual method used to create a dynamic file structure from an existing file. It was
developed to allow a programmer to quickly create a dynamic file structure, assign new attributes as
needed, and then fix the new and updated format. The FillFrom or FixFormat methods must be applied
after the CreateFromFile method is issued.
Example:
CODE
MEMProducts &= new(DynFile)
OPEN(window)
ACCEPT
CASE EVENT()
OF EVENT:Accepted
CASE FIELD()
OF ?FromPeople
[Link]()
[Link]()
[Link](people)
[Link]('MEMProduct')
[Link]('MEMORY')
[Link](people)
TheFile &= [Link]()
SET(TheFile)
[Link](TheFile)
END
END
34 Dynamic File Driver Reference
querystring A STRING constant, variable, or expression that contains a valid SQL statement.
errorcode A LONG value that contains an errorcode, if any. If the dynamic file is created
successfully, a value of zero(0) is returned.
CreateFromSQL is a virtual method that is used to create a dynamic file structure based on the
components of valid SQL querystring. The fields created are extracted from the SELECT criteria, and
keys created are extracted by the ORDER BY clause, and assigned to the dynamic file via the use of a
PROP:SQL property assignment. The syntax of the querystring must match the DRIVER type. The
dynamic file MUST be SQL based, to allow proper processing of the SQL statement.
Implementation: The CreateFromSQL method should be applied after the Driver and Owner attributes of
the dynamic file have been set. These attributes can be set using the DynFile SetDriver and SetOwner
methods.
Example:
CODE
!First, set the query
lQuery='SELECT ProductID , ProductName FROM Products ORDER BY ProductName'
MSProducts &= new(DynFile) !Assign the dynamic file reference
[Link]('MSSQL') !Set the Driver
[Link]('(local),Northwind,sa,') !Set the connect string
[Link](CLIP(lQuery)) !Create the file
Dynamic File Driver Reference 35
CreateKeyComponents is a protected, virtual method used to create the key components used in a
dynamic file structure. It uses the internal queues of the DynFile class to extract necessary key
information, and assigns the appropriate properties to the dynamic file structure.
Implementation: The CreateKeyComponents method is usually called within the CreateStruct method,
and assigns all necessary key component properties just prior to a call to FIXFORMAT.
Example:
SORT([Link], [Link])
rec = RECORDS([Link])
LOOP ndx = 1 TO rec
GET([Link], ndx)
AKey &= [Link]{prop:Key, ndx}
AKey{prop:Type} = CHOOSE(UPPER([Link]) = 'K', 'KEY', 'INDEX')
AKey{prop:Label} = CLIP([Link])
IF CLIP([Link])
AKey{prop:Name} = CLIP([Link])
END
AKey{prop:NoCase} = [Link]
AKey{prop:Opt} = [Link]
AKey{prop:Primary} = [Link]
AKey{prop:Dup} = [Link]
[Link](AKey, [Link])
END
36 Dynamic File Driver Reference
CreateStruct is a virtual and protected method that is used to assign all file, field, key, memo and blob
attributes to a dynamic file structure.
Implementation: The CreateStruct method should be called after all field and key name have been
assigned, and just prior to the FIXFORMAT language statement. In the DynFile class, it is called in the
FixFormat, FillFrom and CreateFromFile methods
Conceptual Example:
[Link] PROCEDURE(FILE pFile)
ndx LONG
ndx2 LONG
Rec LONG
Rec2 LONG
flds LONG
AKey &KEY
CODE
!all file attribute assignments here
flds = pFile{prop:Fields}
LOOP ndx = 1 TO flds
CLEAR([Link])
!all field assignments here
ADD([Link])
END
flds = pFile{PROP:Memos}
LOOP ndx = 1 TO flds
CLEAR([Link])
!all memo/blob assignments here
ADD([Link])
END
rec = pFile{PROP:Keys}
LOOP ndx = 1 TO rec
!all key property and components assignments here
ADD([Link])
END
[Link]() !Create the dynamic file structure from information above
Dynamic File Driver Reference 37
FillFrom Create a dynamic file and fill it with the source’s contents.
sameflag A BYTE value (default is 0 – not the same) that indicates that the dynamic file structure
receiving the contents of the table is the same. This is used to improve record
assignment speed.
errorcode A valid error code is returned if the method encountered any errors.
FillFrom is used to create a dynamic file structure, and load existing data from the dynamic file’s source.
If the parameter is a filelabel, FillFrom will fix the format of the current dynamic file structure, and load the
contents of the referenced filelabel.
If the FillFrom parameter is the reference to the DynFile class, FillFrom also creates all file, field, key
and memo/blob attributes stored in the DynFile Class internal queues, and then proceeded to fix the
format and prime the file with values also stored in the internal queues.
TestFill PROCEDURE
MSProducts &DynFile
MEMProducts &DynFile
TheFile &File
MyQueue QUEUE
productID LONG
ProductName STRING(25)
END
[Link]('MSSQL')
,Northwind,sa,sa2000')
[Link]('(local),Northwind,sa,')
[Link]('SELECT ProductID, ProductName FROM Products')
[Link](true)
[Link]('MEMProduct')
[Link]('MEMORY')
[Link](MSProducts)
38 Dynamic File Driver Reference
DISPOSE(MSProducts)
SET(TheFile)
LOOP
NEXT(TheFile)
IF ERRORCODE()
BREAK
ELSE
[Link]('ProductID', [Link])
[Link]('ProductName', [Link])
ADD(MyQueue)
END
END
OPEN(WINDOW)
ACCEPT
END
DISPOSE(MEMProducts)
OPEN(window)
[Link](?List1)
ACCEPT
CASE EVENT()
OF EVENT:Accepted
CASE FIELD()
OF ?Refresh1
lQuery = lQuery1
Do RefreshQuery
OF ?Refresh2
lQuery = lQuery2
Do RefreshQuery
OF ?Refresh3
lQuery = lQuery3
Do RefreshQuery
OF ?FromPeople
[Link]()
[Link]()
[Link](people)
[Link]('MEMProduct')
[Link]('MEMORY')
[Link](people)
TheFile &= [Link]()
SET(TheFile)
[Link](TheFile)
END
END
END
Dynamic File Driver Reference 39
sameflag A BYTE value (default is 0 – not the same) that indicates that the table structure receiving
the contents of the dynamic file structure is the same. This is used to improve record
assignment speed.
FillTo is used to copy the contents of the active dynamic file into an existing table or queue. The filelabel
must be an existing FILE structure declared in the program. The queuelabel must be an existing QUEUE
structure declared in the program. If the method is successful, it returns no error code (0). Otherwise, an
appropriate file processing error code is returned.
Implementation: FillTo checks to see if the dynamic file exists via the StructCreated property, and if true,
extracts the file’s contents and adds it to the data source identified by the filelabel or
queuelabel parameter. If any error is encountered during this process, an appropriate
error code is returned.
Example:
CODE
sts = STATUS(myFile)
IF sts <> 0
CLOSE(myFile)
END
[Link](myFile)
[Link](‘In-Memory’)
[Link](pName)
[Link](pOwner)
[Link](myFile)
[Link]()
errorcode a valid error code that can be returned by the FIXFORMAT language statement
The FixFormat method fixes the format of a dynamic file just prior to its reference assignment and
creation. It is similar in function to the standard FIXFORMAT language statement, and returns the same
errorcode if applicable. It also checks the StructCreated DynFile property, and if it is not set, it will create
the file structure prior to fixing the format.
Implementation: The FixFormat method is used internally by the DynFile class by the FillFrom methods.
Example:
MyFieldGrp group(TFieldGrp).
MyKeyGrp group(TKeyGrp).
MyMemoGrp group(TMemoGrp).
MyDynFile class(cDynFile)
end
TheFile &File
rBlob &BLOB
AKey &Key
LastError long
locSysID long
locFirstName string(50)
locLastName string(50)
locNotes string(4096)
locDate date
Window WINDOW('Caption'),AT(,,322,185),GRAY,DOUBLE,AUTO
PANEL,AT(6,5,209,67),USE(?Panel1),BEVEL(-1)
STRING('SysID:'),AT(17,18),USE(?String1)
STRING(@n_6),AT(63,18),USE(locSysID)
IMAGE,AT(223,5,87,134),USE(?Image1)
STRING('First Name:'),AT(17,32),USE(?String2)
STRING(@s50),AT(63,32),USE(locFirstName)
STRING('Last Name:'),AT(17,46),USE(?String3)
STRING(@s50),AT(63,46),USE(locLastName)
STRING('Birthday:'),AT(17,58),USE(?String8)
STRING(@d17),AT(63,59),USE(locDate)
STRING('Notes:'),AT(10,76),USE(?String4)
TEXT,AT(10,88,201,52),USE(locNotes),BOXED
BUTTON('Previous'),AT(11,144,45,14),USE(?btnPrev)
BUTTON('Next'),AT(63,144,45,14),USE(?btnNext)
PROMPT('Select Order:'),AT(168,148),USE(?Prompt1)
LIST,AT(223,147,87,10),USE(?List1),DROP(10),FROM('Record Order|kSysID|kName')
BUTTON('Close'),AT(266,163,45,14),USE(?btnClose)
END
Dynamic File Driver Reference 41
CODE
[Link]('TopSpeed')
[Link]('[Link]')
[Link](true)
[Link] = 1
[Link] = 'SysID'
[Link] = 'LONG'
[Link](MyFieldGrp)
[Link] = -1
[Link] = 'NOTES'
[Link] = 'M' ! M is for MEMO
[Link] = 4096 ! memo is 4k in size
[Link](MyMemoGrp)
[Link] = -2
[Link] = 'Photo'
[Link] = 'B' ! B is for blob
[Link] = true
[Link](MyMemoGrp)
! Get a reference to the created file, create the file on disk and open it
TheFile &= [Link]()
create(TheFile)
open(TheFile)
empty(TheFile)
42 Dynamic File Driver Reference
The GetCreate method is used to return the current value of the DynFile bCreate property. If the value
returned is (1) TRUE, then the dynamic file will be able to be created. If the value returned is (0) FALSE,
then the dynamic file must exist before opening it.
The GetDriver method is used to return the current value of the DynFile sDriver property. This property
holds the contents of the dynamic file DRIVER attribute.
The GetEncrypt method is used to return the current value of the DynFile bEncrypt property. If the value
returned is (1) TRUE, then the dynamic file’s ENCRYPT attribute is active. If the value returned is (0)
FALSE, then the dynamic file is not encrypted.
fieldlabel A string constant, variable or expression that identifies the label of a dynamic file field
GetField is used to return the contents of a field label used in a dynamic file, and identified by the
fieldlabel parameter.
Example:
GrabData ROUTINE
DATA
TheFile &FILE
ndx LONG
locANY ANY
CODE
TheFile &= [Link]()
!This should use the TheFile instead the queue
IF [Link] = false
SET(TheFile)
END
LOOP
NEXT(TheFile)
IF ERRORCODE()
BREAK
ELSE
LOOP ndx = 1 TO RECORDS([Link])
GET([Link], ndx)
IF ~ERRORCODE()
locANY &= [Link]([Link])
IF ~(locANY &= null)
[Link]([Link], locANY)
END
END
END
ADD([Link])
RetVal = ERRORCODE()
IF RetVal
BREAK
END
END
END
fieldnumberl A LONG constant, variable or expression that identifies the ordinal field number in a
dynamic file.
fieldcontents A string constant, variable or expression that holds the label of a dynamic file field named
by the fieldnumber.
GetFieldName is used to return the field label used in a dynamic file, identified by the fieldnumber ordinal
position ion the dynamic file.
Example:
fieldlabel A string constant, variable or expression that identifies the label of a dynamic file field
varcontents A reference to an ANY data type used to hold the contents of the field named by the
fieldlabel.
GetFieldValue is a virtual method used to set the contents of a field label used in a dynamic file,
identified by the fieldlabel parameter, to an ANY data type named by the varcontents.
This method is equivalent to the GetField method, but does not return the field contents like GetField,
but instead passes the contents to a variable by address.
Example:
locSysID LONG
locFirstName STRING(50)
locLastName STRING(50)
locNotes STRING(4096)
locDate DATE
CODE
DO AssignData
AssignData ROUTINE
[Link]('SysID', locSysID)
[Link]('FirstName', locFirstName)
[Link]('LastName', locLastName)
[Link]('Birthday', locDate)
?btnPrev{prop:disable} = bof(TheFile)
?btnNext{prop:disable} = eof(TheFile)
GetFileRef returns a reference to a file defined in the DynFile class. After any dynamic file has been
initialized and formatted, processing the dynamic file is implemented with a file reference assignment.
Example:
[Link](true)
[Link]('MEMProduct')
[Link]('MEMORY')
[Link](MSProducts)
DISPOSE(MSProducts)
OPEN(WINDOW)
ACCEPT
END
keyname A string constant, variable, or expression that identifies the key label.
GetFileRef returns a reference to a file defined in the DynFile class. After any dynamic file has been
initialized and formatted, processing the dynamic file in key sequence is implemented with a key
reference assignment.
Example:
CASE EVENT()
OF ?FromPeople
[Link]()
[Link]()
[Link](people)
[Link]('MEMProduct')
[Link]('MEMORY')
[Link](people)
TheKey &= [Link]('PEO:KEYNAME')
IF TheKey &= NULL
MESSAGE('Key is NULL…processing in FILE order')
SET(TheFile)
ELSE
SET(TheKey)
END
[Link](TheFile)
END
48 Dynamic File Driver Reference
The GetName method is used to return the current value of the DynFile sName property. This property
holds the contents of the dynamic file NAME attribute.
The GetOEM method is used to return the current value of the DynFile bOEM property. If the value
returned is (1) TRUE, then the dynamic file’s OEM attribute is active. If the value returned is (0) FALSE,
then the dynamic file’s is not using the OEM attribute.
Implementation: GetOEM can be called at anytime to query the status of a dynamic file’s OEM attribute.
The GetOwner method is used to return the current value of the DynFile sOwner property. This property
holds the contents of the dynamic file OWNER attribute.
Implementation: GetOwner can be used at any time to read the contents of a dynamic file’s OWNER
attribute.
The GetPrefix method is used to return the current value of the DynFile sPrefix property. This property
holds the contents of the dynamic file PRE attribute.
Implementation: GetPrefix can be used at any time to read the contents of a dynamic file’s PRE attribute.
The GetReclaim method is used to return the current value of the DynFile bReclaim property. If the value
returned is (1) TRUE, then the dynamic file’s RECLAIM attribute is active. If the value returned is (0)
FALSE, then the dynamic file’s is not using the RECLAIM attribute.
Implementation: GetReclaim can be called at anytime to query the status of a dynamic file’s RECLAIM
attribute.
The GetCreatedFromSQL method is used to return the current value of the DynFile CreatedFromSQL
property. If the value returned is (1) TRUE, then the dynamic file was created from SQL syntax. If the
value returned is (0) FALSE, then the dynamic file was created using standard DynFile methods.
LoadFile Load existing file with contents from another data source
filelabel The label of a valid FILE that identifies the data target.
drivername A string constant, variable or expression that identifies the name of the file driver that
applies to the data source.
namestring A string constant, variable or expression that contains the operating system device name
for the structure identified by the filelabel to use with the data source.
ownerstring A string constant, variable or expression that contains file encryption password, or SQL
connection string for the data source.
LoadFile is a virtual method that can be used to load an existing table from an alternate data source.
Implementation: LoadFile validates that the data source is opened, then calls the CreateFromFile,
SetDriver, SetName, and SetOwner methods. It then loads the contents of the data
source through the FillTo method.
Example:
fieldname A string constant, variable or expression that identifies the field name to be removed from
the dynamic file definition
RemoveField takes care of all housekeeping needed when removing a field from a dynamic file
definition. First, the method checks if the fieldname is used in any key definitions. If so, it locates and
stores all key names that use it. For each key name where that field is used, a call to the
RemoveKeyField method is made. Also, if the internal File structure is already created, Remove Field
kills the field. Additional housekeeping with the DynFile FieldQ is performed, and key definitions with the
resorted field numbers are also updated.
Example:
CODE
TheFile &= null
[Link]()
[Link]('[Link]')
[Link]('kName', 'FirstName')
[Link]('Birthday')
[Link]('SysID')
[Link]()
TheFile &= [Link]()
CREATE(TheFile)
Dynamic File Driver Reference 53
keyname A string constant, variable or expression that identifies the key name to be removed from
the dynamic file definition
RemoveKey takes care of all housekeeping needed when removing a key from a dynamic file definition,
including proper handling of the key if the dynamic file is already opened, and reindexing of the internal
queues used in the DynFile class.
Example:
CODE
!here is how the original key was created
clear(MyKeyGrp)
[Link] = 2
[Link] = 'kName'
[Link] = 'K' ! K = Key, I = Index
[Link] = true
[Link](MyKeyGrp)
! Add the fields in the key
[Link]('kName', 'LastName', true, 1)
[Link]('kName', 'FirstName', true, 2)
RemoveElements ROUTINE
[Link]('[Link]')
[Link]('kName')
[Link]('Birthday')
[Link]('SysID')
[Link]()
TheFile &= [Link]()
CREATE(TheFile)
54 Dynamic File Driver Reference
keyname A string constant, variable or expression that identifies the key label containing
the field to remove.
fieldname A string constant, variable or expression that identifies the field name to be
removed from the keyname in the dynamic file definition
RemoveKeyField takes care of all housekeeping needed when removing a key field from a dynamic file
key definition, including a check to see if removing the field will remove all fields from the target key, and
continues to remove the key itself if appropriate.
Example:
[Link]('[Link]')
[Link]('kName','FirstName')
[Link]('Birthday')
[Link]('SysID')
[Link]()
TheFile &= [Link]()
CREATE(TheFile)
Dynamic File Driver Reference 55
ResetAll is a virtual method that clears all internal field, key, and memo queues that are used to hold the
needed properties and values needed by the DynFile class to create the target structure. This method
should be used like an initialization method before creating any new dynamic file.
Example:
CODE
[Link]()
[Link] = false
[Link] = pFile{prop:Driver}
[Link] = pFile{prop:Create}
[Link] = pFile{prop:Reclaim}
[Link] = pFile{prop:Encrypt}
56 Dynamic File Driver Reference
drivername A string constant, variable or expression that identifies the name of the file driver to use
with the data source named by the filelabel.
namestring A string constant, variable or expression that contains the operating system device name
for the structure identified by the filelabel to use with the data source.
ownerstring A string constant, variable or expression that contains file encryption password, or SQL
connection string for the data source.
SaveFile is a virtual method that can be used to load an existing table from an alternate data source.
Implementation: SaveFile validates that the data source is opened, then calls the CreateFromFile,
SetDriver, SetName, and SetOwner methods. It then writes the contents of the dynamic
file to the data source through the use of the FillFrom method.
Example:
The SetCreate method is used to set the current value of the DynFile bCreate property. A value of (1) will
allow the dynamic file to be created. If set to zero (0), the dynamic file created will have to match an
existing file.
Implementation:
SetCreate is used to set the dynamic file CREATE attribute.
Example:
[Link](true)
[Link]('MEMProduct')
[Link]('MEMORY')
[Link](MSProducts)
58 Dynamic File Driver Reference
drivername A string constant, variable or expression that identifies the name of the file driver to use
with the dynamic file. Optionally, the drivername can also be a variable parameter
(passed by address) if needed.
The SetDriver method is used to set the database driver used for the dynamic file. The drivername must
contain a valid string that identifies the driver type (i.e., ‘Topspeed’, ‘MSSQL’, etc.). See the Database
Drivers PDF for more information.
The SetDriver method should also be used with the filelabel parameter to set the driver property when
the application is linked in local mode. The file passed as a parameter can be any file defined in the
application that is also using the driver needed to create the dynamic file.
Implementation: SetDriver sets either the PRIVATE sDriver or sFileDriver property, based on the
parameter type used. The appropriate property is used in the CreateStruct method to
initialize the DRIVER attribute of the target dynamic file. You can override the default
SetDriver method in appropriate embed points prior to the LoadDynamicFiles and
SaveDynamicFiles template generated procedures.
[Link]('TopSpeed')
[Link]('[Link]')
[Link](true)
dummy FILE,DRIVER('MSSQL')
RECORD
END
END
MyDynFile &DynFile
lQuery STRING(128)
CODE
[Link](dummy)
[Link]('(local),Northwind,sa,')
[Link](CLIP(lQuery))
Dynamic File Driver Reference 59
flag A BYTE value or EQUATE that controls the ENCRYPT attribute for a dynamic file. If set
to TRUE (1), the dynamic file’s contents will be encrypted.
SetEncrypt sets the internal bEncrypt property in the DynFile class. When the CreateFromFile or
CreateStruc methods are called, this property is used to set the dynamic file’s ENCRYPT attribute.
The SetOwner method must also be set properly for the SetEncrypt method to be valid. For more details,
please refer to the Language Reference PDF for information regarding the dependency of OWNER with
ENCRYPT.
Example:
CODE
[Link]('TopSpeed')
[Link]('[Link]')
[Link]('mypassword')
[Link](TRUE)
[Link](TRUE)
fieldname A string constant, variable, or expression that identifies the name of the dynamic file field
that will be initialized with the contents of the fieldvalue parameter.
fieldvalue A string constant, variable, or expression that contains the contents to add to the target
fieldname.
SetFieldValue is used to enter a default value into a dynamic file’s target fieldname. If the field name is a
numeric type, proper formatting should also be applied.
Example:
! Get a reference to the created file, create the file on disk and open it
TheFile &= [Link]()
CREATE(TheFile)
OPEN(TheFile)
EMPTY(TheFile)
CLEAR(TheFile)
[Link]('SysID', 1)
[Link]('FirstName', 'Bob')
[Link]('LastName', 'Jones')
[Link]('Birthday', date(05,08,1956))
ADD(TheFile)
IF ERRORCODE()
MESSAGE('Errorcode in add = ' & errorcode())
END
nameattribute A string constant, variable or expression that contains the operating system device name
for the structure identified by the label to use with the dynamic file. Optionally, this
parameter can also be a variable parameter (passed by address) if needed.
The SetName method is used to set the operating system device name for the structure identified by the
label to use with the dynamic file.
Implementation: SetName sets the PRIVATE sName property, and is used in the CreateStruct method to
initialize the NAME attribute of the target dynamic file structure.
Example:
CODE
[Link]('TopSpeed')
[Link]('[Link]')
[Link](true)
flag A BYTE value or EQUATE that controls the OEM attribute for a dynamic file. If set to
TRUE (1), the dynamic file’s will use the OEM ANSI translation.
SetOEM is used to enable OEM translation for the target dynamic file structure.
Implementation: SetOEM sets the private bOEM property, and is used in the CreateStruct method to
initialize the OEM attribute of the target dynamic file.
Example:
CODE
[Link]('TopSpeed')
[Link]('[Link]')
[Link](TRUE)
[Link](true)
SetOwner Set file encryption password, or SQL connection string for a dynamic file
ownerstring A string constant, variable or expression that contains file encryption password, or SQL
connection string for the dynamic file. Optionally, the ownerstring can also be a variable
parameter (passed by address) if needed.
The SetOwner method is used to initialize the OWNER attribute for the target dynamic file structure. The
OWNER attribute is traditionally used to encrypt the file’s header, but in SQL based targets it is used to
hold the connection string information.
Implementation: SetOwner sets the private sOwner property, which is used in the CreateStruct method
to initialize the OWNER attribute of the target dynamic file.
Example:
CODE
ACCEPT
CASE EVENT()
OF EVENT:Accepted
CASE FIELD()
OF ?Refresh1
lQuery = lQuery1
Do RefreshQuery
END
END
END
RefreshQuery ROUTINE
[Link]()
[Link]()
[Link]()
[Link]()
[Link]('MSSQL')
[Link]('(local),Northwind,sa,')
[Link](CLIP(lQuery))
[Link](true)
[Link]('MEMProduct')
[Link]('MEMORY')
[Link](MSProducts)
name A string constant, variable or expression that identifies the label prefix to use with the
dynamic file. Optionally, the name can also be a variable parameter (passed by address)
if needed.
The SetPrefix method is used to set the label prefix (PRE attribute) used for the dynamic file.
Implementation: SetPrefix sets the private sPrefix property, which is used in the CreateStruct method to
initialize the PRE attribute of the target dynamic file.
Example:
CODE
[Link]('TopSpeed')
[Link]('TES')
[Link]('[Link]')
[Link](TRUE)
64 Dynamic File Driver Reference
flag A BYTE value or EQUATE that sets the RECLAIM attribute for a dynamic file. If set to
TRUE (1), the dynamic file will reuse deleted record space.
SetReclaim is used to allow the reuse of deleted record space for the target dynamic file structure.
Implementation: SetReclaim sets the private bReclaim property, which is used in the CreateStruct
method to initialize the RECLAIM attribute of the target dynamic file.
Example:
code
[Link]('TopSpeed')
[Link]('[Link]')
[Link](TRUE)
[Link](true)
string A string constant or variable that contains information to send to the DEBUGVIEW utility.
Trace allows the class to send debug information to DebugView. DebugView is an external industry
standard program used to analyze 32-bit Windows executables.
Implementation: Trace can be used anytime after the DynFile class has been initialized.
Example:
ThisDyn Class(DynFile)
End
DynWaitWindow WINDOW('Please Wait'),AT(,,116,18),FONT('MS Sans Serif',8,,FONT:regular),|
CENTER,GRAY,DOUBLE
STRING('Please Wait: Caching Tables.'),AT(0,3,116,12),USE(?DynWaitString),TRN,CENTER
END
CODE
c = clock()
[Link]('ReportDepartmentsFast')
[Link] = GlobalRequest ! Store the incoming request
ReturnValue = [Link]()
IF ReturnValue THEN RETURN ReturnValue.
[Link] = ?Progress:Thermometer
[Link] &= VCRRequest
[Link] &= GlobalErrors !Set this windows ErrorManager to global ErrorManager
CLEAR(GlobalRequest) ! Clear GlobalRequest after storing locally
CLEAR(GlobalResponse)
OPEN(DynWaitWindow)
DISPLAY()
[Link]('Caching files prior to generating report')
[Link](Employee,'TOPSPEED',,)
[Link](LinkEmpDept,'TOPSPEED',,)
CLOSE(DynWaitWindow)
Relate:[Link]()
66 Dynamic File Driver Reference
UnfixFormat is used to close the current dynamic file reference, and clear its current structure contents.
Implementation: UnfixFormat closes and clears the dynamic file structure that was created by the
FixFormat method.
Example:
MSProducts &DynFile
CODE
[Link]()
!…do some stuff here
[Link]()
Dynamic File Driver Reference 67
ViewFormat is virtual method used to extract the FILE structure of an active dynamic file. All elements of
a Clarion FILE structure are extracted, with the exception of the file label.
Sample Format:
FILE,DRIVER('TOPSPEED'),PRE(),CREATE,NAME('[Link]')
DEP:KEY KEY(+DEP:DEPARTMENT),NOCASE,OPT,PRIMARY
DEP:DESCKEY KEY(+DEP:DESCRIPTION),NOCASE,OPT
Record RECORD,PRE()
DEP:DEPARTMENT LONG
DEP:DESCRIPTION STRING(30)
END
Implementation: ViewFormat should be called after the Dynamic file structure has been initialized. You
should also concatenate a label name to complete the full FILE structure.
Example:
Annotated Examples
Note: Each of the examples listed here are included with your Dynamic File Driver install.
This program reads an existing FILE structure, and writes the structure to an ASCII file. The ASCII file is
the dynamic file created in this example.
PROGRAM
MAP
DumpFileDefinition PROCEDURE(FILE f, STRING dest)
END
Employee FILE,DRIVER('TOPSPEED'),NAME('[Link]'),PRE(EMP),BINDABLE,CREATE,THREAD
EmpID_Key KEY(EMP:EmpID),PRIMARY
EmpName_Key KEY(EMP:Lname,EMP:Fname,EMP:MInit),DUP
JobID_Key KEY(EMP:JobID),DUP
PubID_Key KEY(EMP:PubID),DUP
DateKey KEY(-EMP:Hire_date),DUP,NOCASE,OPT
MyMemo MEMO(2000)
MyBlob BLOB,BINARY
Record RECORD,PRE()
EmpID CSTRING(10)
Fname CSTRING(21)
MInit CSTRING(2)
Lname CSTRING(31)
JobID SHORT
Job_lvl BYTE
PubID CSTRING(5)
Hire_date DATE
PictureFile STRING(65)
END
END
LineSize EQUATE(255)
FileIndent EQUATE(20)
The CLASS declaration contains methods that use FILE and KEY properties to extract the information from the target
FILE structure (the TopSpeed file in this example). These methods are launched from the DumpFileDefinition method:
FileDumper CLASS
TheFile &FILE,PRIVATE
Dest &FILE,PRIVATE
Line ANY,PRIVATE
DumpFileDetails PROCEDURE,PRIVATE
DumpKeys PROCEDURE,PRIVATE
DumpMemosBlobs PROCEDURE,PRIVATE
DumpGroupDetails PROCEDURE(USHORT start, USHORT total),PRIVATE
DumpFieldDetails PROCEDURE(USHORT indent, USHORT FieldNo),PRIVATE
DumpToFile PROCEDURE,PRIVATE
SetAttribute PROCEDURE(SIGNED Prop,STRING Value),PRIVATE
StartLine PROCEDURE(USHORT indent,STRING label, STRING type),PRIVATE
Concat PROCEDURE(STRING s),PRIVATE
Construct PROCEDURE
Destruct PROCEDURE
DumpFileDefinition PROCEDURE(FILE f, STRING dest)
END
70 Dynamic File Driver Reference
The main program contains two lines. The last line simply lets you know that it is completed.
CODE
DumpFileDefinition needs the label of the source file (Employee), and the destination to write the structure to
(‘[Link]’)
DumpFileDefinition(Employee,'[Link]')
MESSAGE('Program Completed')
The constructor begins to create the dynamic file, setting up the ASCII file characteristics:
[Link] PROCEDURE()
fGroup &GROUP
CODE
[Link] &= NEW(FILE)
[Link]{PROP:Driver} = 'ASCII'
[Link]{PROP:Create} = TRUE
[Link]{PROP:Type, 1} = 'STRING'
[Link]{PROP:Size, 1} = LineSize
FIXFORMAT sets up the structure in memory. It does not CREATE or OPEN the file.
FIXFORMAT([Link])
ASSERT(ERRORCODE()=0, 'FixFormat failed with error ' & FILEERRORCODE())
fGroup &= [Link]{PROP:Record}
[Link] &= WHAT(fGROUP, 1)
At program end, the destructor disposes the file object created by the NEW statement:
[Link] PROCEDURE()
CODE
DISPOSE([Link])
[Link] &= NULL
The dynamic file is opened, created if needed, and then the properties of the TopSpeed file are extracted and saved to
the ASCII file in sequence.
[Link] PROCEDURE(FILE f, STRING dest)
CODE
[Link]{PROP:Name} = dest
[Link] &= f
OPEN([Link])
IF ERRORCODE()
CREATE([Link])
OPEN([Link])
END
ASSERT(ERRORCODE()=0, 'OPEN Dest failed with error ' & ERROR())
[Link]
[Link]
[Link]
[Link](0, F{PROP:Fields})
[Link](FileIndent,'','END')
[Link]
CLOSE([Link])
Dynamic File Driver Reference 71
Here we see the properties that you can use to create a dynamic file.
[Link] PROCEDURE
CODE
[Link](FileIndent, 'Employee', 'FILE')
[Link](',DRIVER(''' & CLIP([Link]{PROP:Driver}))
IF [Link]{PROP:DriverString}
[Link](',' & CLIP([Link]{PROP:DriverString}))
END
[Link](''')')
[Link]([Link]{PROP:Create},'CREATE')
[Link]([Link]{PROP:Reclaim},'RECLAIM')
IF [Link]{PROP:Owner}
[Link](',OWNER(''' & CLIP([Link]{PROP:Owner}) & ''')')
END
[Link]([Link]{PROP:Encrypt},'ENCRYPT')
[Link](',NAME(''' & CLIP([Link]{PROP:Name}) & ''')')
[Link]([Link]{PROP:Thread},'THREAD')
[Link]([Link]{PROP:OEM},'OEM')
[Link]
[Link] PROCEDURE
x UNSIGNED,AUTO
CODE
LOOP X = 1 TO ([Link]{PROP:Memos} + [Link]{PROP:Blobs})
IF UPPER ([Link]{PROP:type, -X}) = 'MEMO'
[Link](FileIndent+2, [Link]{PROP:label, -X}, 'MEMO(')
[Link](CLIP([Link]{PROP:Size, -X})&')')
END
IF UPPER ([Link]{PROP:type, -X}) = 'BLOB'
MESSAGE('BLOB FOUND')
[Link](FileIndent+2, [Link]{PROP:label, -X}, 'BLOB')
END
[Link]([Link]{PROP:Binary,-X}, 'BINARY')
IF [Link]{PROP:Name, -X}
[Link](',NAME(''' & CLIP([Link]{PROP:Name, -X}) & ''')')
END
[Link]
MESSAGE('MEMO WRITE')
END
[Link] PROCEDURE
x UNSIGNED,AUTO
y UNSIGNED,AUTO
aKey &KEY
CODE
LOOP x = 1 TO [Link]{PROP:Keys}
AKey &= [Link]{PROP:Key, x}
[Link](FileIndent+2, AKey{PROP:label}, AKey{PROP:Type})
[Link]('(')
LOOP y = 1 TO AKey{PROP:Components}
IF y > 1 THEN [Link](',').
IF AKey{PROP:Ascending, y}
[Link]('+')
ELSE
[Link]('-')
END
[Link]([Link]{PROP:Label, akey{PROP:Field, y}})
END
[Link](')')
[Link](AKey{PROP:Dup},'DUP')
[Link](AKey{PROP:NoCase},'NOCASE')
[Link](AKey{PROP:Opt},'OPT')
[Link](AKey{PROP:Primary},'PRIMARY')
IF AKey{PROP:Name}
72 Dynamic File Driver Reference
[Link] PROCEDURE
CODE
ADD([Link])
ASSERT(ERRORCODE()=0, 'Could not add to dump file: ' & ERROR())
74 Dynamic File Driver Reference
Dynamic File Driver Reference 75
This program has SQL queries stored in a queue, and one static ISAM file definition. All of these
parameters are used to create a dynamic file, which is then loaded into a virtual list box, or VLB (a list box
that is created and formatted at run time).
Although this program is an excellent tutorial to learn how to create VLBs, our annotated example
comments will only focus on the dynamic file driver elements.
PROGRAM
MAP
FillVirtualListBox PROCEDURE()
END
CODE
FillVirtualListBox()
The FillVirtualListBox procedure begins with the ISAM FILE and CLASS declarations:
FillVirtualListBox procedure
People FILE,DRIVER('TOPSPEED'),PRE(PEO),CREATE,BINDABLE,THREAD
KeyId KEY(PEO:Id),NOCASE,OPT,PRIMARY
KeyLastName KEY(PEO:LastName),DUP,NOCASE
Record RECORD,PRE()
Id LONG
FirstName STRING(30)
LastName STRING(30)
Gender STRING(1)
END
END
MSProducts &DynFile
MEMProducts &DynFile
TheFile &File
TheKey &Key
MyQueue QUEUE
productID LONG
ProductName STRING(25)
END
A class is declared here to simplify processing the list box format strings and refreshing when needed.
!=== VLB ========
DynFileList CLASS
Changed BYTE
ListControl USHORT
File &File
Key &Key
Init PROCEDURE(UNSIGNED TheList)
Refresh PROCEDURE(*FILE TheDynFile),VIRTUAL
FormatColumn PROCEDURE(STRING Label,STRING DataType,|
USHORT DataSize,BYTE Places),STRING,VIRTUAL
VLBProc PROCEDURE(LONG ROW, SHORT COL), STRING, VIRTUAL, PROC
END
76 Dynamic File Driver Reference
lQuery CSTRING(200)
INIEntrys LONG
INIEntrysIndex LONG
lFound BYTE
CODE
First Load any existing queries from an INI file:
DO LoadQueryList
OPEN(window)
GET(QueryQueue,1)
?Query:Combo{PROP:ScreenText}=[Link]
(?Query:Combo{PROP:ListFeq}){PROP:SELECTED}=1
[Link](?List1)
ACCEPT
CASE EVENT()
OF EVENT:Accepted
CASE FIELD()
If the Refresh button is pressed, we need to make sure that there is a valid Query string before we
attempt to create the Dynamic File
OF ?Refresh
lFound = FALSE
!Search for Combo text in the queue
LOOP INIEntrysIndex=1 TO RECORDS(QueryQueue)
GET(QueryQueue,INIEntrysIndex)
IF NOT ERRORCODE()
IF ?Query:Combo{PROP:VALUE}=[Link]
lFound = TRUE
!Move query to first place
DELETE(QueryQueue)
Dynamic File Driver Reference 77
[Link]=?Query:Combo{PROP:VALUE}
ADD(QueryQueue,1)
(?Query:Combo{PROP:ListFeq}){PROP:SELECTED}=1
BREAK
END
END
END
!If the combo text was not found in the queue add it
IF lFound=False
[Link] = ?Query:Combo{PROP:VALUE}
ADD(QueryQueue,1)
END
lQuery = [Link]
Call the ROUTINE to create the dynamic file after getting a valid query:
DO RefreshQuery
OF ?FromPeople
This method reads the “people” structure, and calls FIXFORMAT to establish the new structure
[Link](people)
The next two methods change the name attribute and driver type before opening and processing the
dynamic file
[Link]('MEMProduct')
[Link]('MEMORY')
The FillFrom method opens the new “In-Memory” dynamic file, and loads the contents of the people file
into it.
[Link](people)
Finally we use assign the file refernce to the file used in the VLB:
TheFile &= [Link]()
[Link](TheFile)
END
END
END
Do SaveQueryList
LoadQueryList ROUTINE
INIEntrys = GETINI( 'QUERYLIST','QUERYRECORDS',0,'.\[Link]')
FREE(QueryQueue)
LOOP INIEntrysIndex=1 TO INIEntrys
[Link]=GETINI( 'QUERYLIST','QUERY'&INIEntrysIndex,'','.\[Link]')
ADD(QueryQueue)
END
The RefreshQuery ROUTINE creates two dynamic files. The MSProducts dynamic file is MSSQL, and
needs to be created so that the CreateFromSQL method can correctly construct the table using
PROP:SQL.
The second dynamic file loads the contents of the first into a memory file that is used with the VLB.
RefreshQuery ROUTINE
[Link]()
[Link]()
[Link]()
[Link]()
[Link]('MSSQL')
[Link]('(local),Northwind,sa,')
[Link](CLIP(lQuery))
[Link](true)
[Link]('MEMProduct')
[Link]('MEMORY')
[Link](MSProducts)
TheFile &= [Link]()
[Link](TheFile)
CODE
CASE ROW
OF -1
IF NOT [Link] &= NULL
SET(TheFile)
lRecords=RECORDS([Link])
RETURN lRecords
ELSE
RETURN 0
END
OF -2
IF NOT [Link] &= NULL
RETURN [Link]{PROP:Fields}
ELSE
RETURN 1
END
OF -3
IF NOT [Link] &= NULL
IF [Link]
[Link] = False
RETURN TRUE
END
END
RETURN FALSE
ELSE
IF NOT [Link] &= NULL
locGroup &= [Link]{prop:Record}
GET([Link], ROW)
IF NOT ERRORCODE()
AttrString &= WHAT(locGroup, COL)
RETURN AttrString
ELSE
MESSAGE(ERRORCODE())
END
ELSE
RETURN ''
END
END
RETURN ''
OF 'DATE'
lPicture = 'd17'
lWidth = LEN(Label)*5
lJustification='R'
OF 'TIME'
lPicture = 't7'
lWidth = LEN(Label)*5
lJustification='R'
OF 'LONG'
lPicture = 'n-14'
lWidth = LEN(Label)*5
lJustification='R'
OF 'ULONG'
lPicture = 'n13'
lWidth = LEN(Label)*5
lJustification='R'
OF 'SREAL'
lPicture = 'n10.2'
lWidth = LEN(Label)*5
lJustification='R'
OF 'REAL'
lPicture = 'n10.2'
lWidth = LEN(Label)*5
lJustification='R'
OF 'DECIMAL'
lPicture = 'n10.2'
lWidth = LEN(Label)*5
lJustification='R'
OF 'PDECIMAL'
lPicture = 'n10.2'
lWidth = LEN(Label)*5
lJustification='R'
OF 'BFLOAT4'
lPicture = 'n10.2'
lWidth = LEN(Label)*5
lJustification='R'
OF 'BFLOAT8'
lPicture = 'n10.2'
lWidth = LEN(Label)*5
lJustification='R'
OF 'STRING'
lPicture = 's'&DataSize
lWidth = DataSize*5
OF 'CSTRING'
lPicture = 's'&(DataSize+1)
lWidth = DataSize*5
OF 'PSTRING'
lPicture = 's'&(DataSize+1)
lWidth = DataSize*5
OF 'MEMO'
lPicture = 's250'
lWidth = 80
! OF 'GROUP'
! OF 'BLOB'
ELSE
END
RETURN CLIP(lWidth&lJustification&'('&lIndent&')|M~'&Label&'~@'&lPicture&'@')
Dynamic File Driver Reference 81
Extended ERRORCODES
If an ERRORCODE value of 47 is returned ('Invalid File Declaration') during any attempted access of a
dynamic file structure, you can use the FILEERRORCODE statement to check for more information.
The next few pages display a table of extended error codes, with their corresponding CLAMSG number,
default error message, and notes
SYSTEM S00001 1000001 Internal Error: This indicates a fatal error please report it to
Property SoftVelocity.
cannot be set
S00002 1000002 Dynamic File You are trying to change the driver of a static file
Support Not without having the Dynamic File Driver support
Found library present.
This error code is returned by
file{PROP:Driver} = 'value'.
FILE S00001 1100001 No File Driver
Specified
S00002 1100002 File Driver The system could not load the file driver DLL.
could not be Probably because it is not on the path
loaded
S00003 1100003 The DLL is not This normally indicates a corrupt file driver
a valid file
driver
S00004 1100004 File Driver not The value specified in file{PROP:Driver} does not
defined match any know driver. If you have a third party file
driver you may need to add an entry to the list of
drivers stored in the windows registry at
"HKEY_LOCAL_MACHINE\Software\SoftVelocity\
AnyDriver\\C60"
Below is a table of Dnumber error codes, with their corresponding CLAMSG number, default error
message
Index:
AddField ...........................................................28 GetPrefix .......................................................... 49
AddFieldToKey.................................................29 GetReclaim ...................................................... 49
AddKey.............................................................30 Load File .......................................................... 20
AddMemo .........................................................31 LoadDynamicFiles ........................................... 20
CacheFile .........................................................32 LoadFile ........................................................... 51
CreateFromFile ................................................33 local link ........................................................... 25
CreateFromSQL...............................................34 local mode.................................................. 20, 58
CreateKeyComponents....................................35 Register
CreateStruct .....................................................36 Templates..................................................... 19
Driver RemoveField.................................................... 52
Dynamic File...................................................5 RemoveKey ..................................................... 53
DynaDriver RemoveKeyField.............................................. 54
defined ..........................................................19 ResetAll............................................................ 55
Dynamic File Driver SaveDynamicFiles ........................................... 20
Uses................................................................5 SaveFile ........................................................... 56
Dynamic File Driver Global Extension .............20 SetCreate......................................................... 57
DynFile Class ...................................................27 SetDriver .......................................................... 58
Methods ........................................................28 SetEncrypt ....................................................... 59
Properties .....................................................27 SetFieldValue................................................... 60
Examples..........................................................69 SetName .......................................................... 61
FillFrom ............................................................37 SetOEM ........................................................... 61
FillTo.................................................................39 SetOwner ......................................................... 62
FixFormat .........................................................40 SetPrefix .......................................................... 63
FIXFORMAT ................................................6, 13 SetReclaim....................................................... 64
GetCreate.........................................................42 Setup.............................................................. 5, 6
GetCreatedFromSQL .......................................50 support templates ............................................ 19
GetDriver ..........................................................42 TFieldGrp ......................................................... 28
GetEncrypt .......................................................42 Trace................................................................ 65
GetField............................................................43 UnfixFormat ..................................................... 66
GetFieldName ..................................................44 UNFIXFORMAT ............................................... 13
GetFieldValue ..................................................45 Uses
GetFileRef ..................................................46, 47 of DFD ............................................................ 5
GetName ..........................................................48 of templates.................................................. 25
GetOEM ...........................................................48 View Format..................................................... 67
GetOwner .........................................................48
86 Dynamic File Driver Reference