October 2001: Volume 11 Number 3

Miscrosoft and the new internet | More power to CCA menus | PFX data and other applications | Disk space limitation fix | Technical tip no.42 | Products Update

Microsoft And The New Internet

David Bennett – Powerflex Corporation – Australia

Is the Internet dead? If you believe the more pessimistic commentators, the Internet was just a bubble, a passing fad. Once we get used to having it around it will still be useful, like a fax machine or a mobile phone, but nothing special.

Microsoft doesn't think so. Microsoft has spent the last several years and a sizeable portion of its multi-billion dollar development budget on its new vision for the Internet, which it calls Microsoft.NET. So what is that, and why should we care?

Microsoft.NET is basically 3 things. First, it's Microsoft's grand vision for a new software architecture for the Internet. As such, it's something to energise the troops, to provide focus and direction that has been lacking for a while.

Microsoft.Net is a vision, the platform and applications

Secondly, it's a new software platform. This includes a new development system called Visual Studio.NET, new languages including C# (C-sharp) and Visual Basic.NET, a Common Language Runtime which is portable across languages and processors, ADO.NET, ASP.NET, Web Services, integrated XML support and more.

Thirdly, it's a set of applications which are intended to both illustrate the power of the platform and stake out Microsoft's turf. The main ones available so far are Web Services called My Services (formerly Hailstorm), "designed to help businesses deepen customer relationships and improve operational efficiency". They support common requirements such as auth-entication, authorisation, notification and preferences. More will follow.

A new platform means new opportunities

Some of those pessimistic commentators dismiss Microsoft.NET as just more smoke and mirrors. Others recognise that Microsoft is taking this very seriously, and has literally "bet the farm". If they're right, Microsoft.NET and My Services are going to be as much a part of our lives ten years from now as Windows and Office are today.

So where does that leave the enterprising developer? With an incredible opportunity, that's where. A major new development platform always creates openings for those who can move quickly. The new technology allows new applications to be written, old applications to be rewritten, new services to be provided, new devices to be created and used to full advantage.

Time to get prepared

The first things to do is to read and understand. Start with the Microsoft Web site and follow the links from there. Secondly, get a copy of Visual Studio.NET and take it for a trial run. Thirdly, look for the opportunities. Talk to your customers and your partners. Talk to us.

Powerflex Corporation has been working closely with Microsoft for some time now to take advantage of this opportunity. We shall be making a major announcement early next year, once Microsoft.NET has been officially released. Stay tuned.

Top of Page

More power to CCA menus

David Roberts – Powerflex Corporation – Australia

The action argument of a CCA menu option covers the full range of Chains, keypoke and event calling which in most cases are quite sufficient for the running of a program. With more complex programs this may well prove lacking in power.

This proved to be the case when developing the Windows version of the Toolbox. In that program each tab is controlled by its own procedure. These procedures are set up as sub-programs each with its own set of keyprocs.

The configuration of a CCA program is such that the Menu ActionBar is global to the whole program. While the Menu contents can be changed at runtime to suit individual subforms or procedures, the action of the menu is still global.

So the task was to find a way to channel menu actions back to the currently active tab. We did this by associating EVENT actions with menu options.

The basic steps

Basically all events triggered by the menu system using the EVENT action are picked up in a common event in the program. Within that event, the event number is passed to a global integer and then an assigned keyproc within the active procedure is called. Once in the keyproc, a switch statement is used to pick up the event number and execute the appropriate action.

Step one is to identify event numbers to be used in the program. An event has been defined in EVENTS.PFI, EVP_CCABASE, which is intended for use in a CCA system. This is used to build up our event list.

#replace EV_OPEN (EVP_CCABASE+50)
#replace EV_SAVEAS (EVP_CCABASE+51)
#replace EV_SAVE (EVP_CCABASE+52)
#replace EV_SAVEAS (EVP_CCABASE+53)

We suggest you start at +50 to ensure that you do not reuse numbers already used in CCA.PFI.

In CCAMENU.MKD an event action would be set up as follows.

+"Save As","EVENT CCABASE+51","",

Inside the MENUBARS module this is evaluated to produce the actual event number, in this case 60251.

Getting back to the program, we next choose a keyproc that will be used to capture and execute the intended event action. In Toolbox we used KEY.SHOW as this is not normally used for other purposes. We used the KEYMAP statement to ensure that the keyproc would not be accidentally triggered.

Key_Map Key.Show to 255 KIP_TERM

The common event is then structured. This is positioned in the main body of the program.

Event EV_OPEN EV_SAVEAS EV_SHELL EV_VIEWFD
EventNo = $CURRENT_EVENT
keypoke MBS_GETFLEXKEY(FK_Show)
end_event

And then the keyproc.

Keyproc Key.Show
Switch EventNo
when EV_OPENB

when EV_SAVEAS

when EV_SAVE

when EV_VIEWFD

endswitch
entagain
return

Using this process greatly increases the potential of a CCA menu system by getting over the limited number of available keyprocs.

Top of Page

Powerflex data and other applications

Max Thomson – Powerflex Corporation – Australia

As a successful developer you have probably come across the need to use the data generated by a Powerflex application in another application. Sometimes you wish to add functionality with additional reports or it may be a customer who demands that only the pie chart generator in a given product will do what they want. Whatever the reason the solution involves reading and/or writing data from a Powerflex file.

The PFXplus standard product can use native database files using DAT and K files and also supports Btrieve files. PFXplus with the SQL added-on can use SQL databases such as Microsoft SQL Server, IBM's DB2 and ORACLE. It is usually possible to read the data generated by PFXplus in Btrieve and SQL databases using the tools provided by the vendors of these products plus a number of third party tools. Depending on the field types it is a little more difficult to write data with these tools that PFXplus can use.

Powerflex Corporation has a number of products that can be used to assist in transferring data to and from other applications. The one you should choose depends a lot on the answers to the following questions.

  1. Is this an ongoing requirement - every hour, day, month or once off?
  2. Does the process need to be automated?
  3. Is there a requirement to write as well as read the data?
  4. Does the application that you wish to import the data into have the ability to use certain types of databases such as ODBC or only comma delimited data files.
  5. Does the product that you wish to import the data into, have a programming language that can be used to run Windows DLL's?

In order to perform a once off transfer of data into a product that only reads comma delimited data, you can use PFXplus, which is quite capable of doing this task with a relatively simple program. If you prefer not to do this, or there is need for some haste, Powerflex Corporation provides a service which can produce the comma delimited data from your Powerflex data files - contact us for details.

Often you need to view (and possibly change) data from Powerflex data files. In this case PFXbrowse may be what you require. This product allows you to view (and optionally edit) data in a grid display. You can also view the file, field and index definitions, sort your view of the data by index and even reindex the file.

Crystal reports driver

Crystal Reports from Seagate provides excellent reporting capabilities and can be used with Powerflex data to produce comprehensive reports. We sell an add-on for Crystal Reports, which can read Powerflex data formats and interfaces directly into the Crystal Reports Product. The driver uses index finds for increased speed.

ODBC driver

Many products can accept data through ODBC and Powerflex Corporation sells an ODBC driver, which can be used to both read and write Powerflex data. The driver is able to do selects by fieldnames using joins with multiple data files and uses indexes to jump in/jump out and sort where appropriate. Like all SQL type drivers the speed of access is not as good as the raw ISAM used by PFXplus but the driver gives good performance and may be the simplest way to read/write data. Assuming the importing application supports it, this method of access delivers real-time data from the Powerflex data files.

Powerflex C libraries

The Powerflex C-Libraries (PFX C-lib) give the greatest flexibility and performance where the importing application supports the loading of Windows DLLs (such as Visual Basic, Excel or Word) or where you are using some form of UNIX. PFX C-lib is the library that provides the lightening fast database access in PFXplus and can do everything that the PFXplus lower database operations can do. This includes creating new files, adding and removing fields and indexes, removing all data from the file as well as reading, deleting, updating and adding data. In the Windows version this product comes as a DLL and can support any application that can make standard calls to a DLL.

The calling sequences are very familiar to developers who are used to using PFXplus as it uses a similar code structure.

Conclusion

In conclusion, Powerflex Corporation offers a number of alternative ways to share data with other applications. If you would like to discuss how one of these products can help you please contact us, or one of our Dealers. If you have a problem sharing Powerflex data with another application and the solutions offered here do not appear to meet your requirements, please speak to us and give us the details of what you wish to do. We may be able to come up with another solution.

Top of Page

Disk space limitation fix

Andrew Schwartz - Grow Biz International Inc. - USA

Hard disk capacities have been increasing exponentially since they were invented. About every ten years or so we run into a problem where software can no longer deal with larger capacities of the current generation of disks. The last time I had to rewrite a disk space function was when a new version of MS-DOS was released that supported more than 32 Megabytes per partition. The current limitation of the DISK_SPACE command is primarily due to the use of 32-bit integers. A 32-bit operating system function limits the maximum size reportable for a disk to 2Gigabytes. For a disk larger than that, the value reported will be wrong. To support larger disks, a 64-bit value needs to be retrieved.

When using Microsoft Windows 95 OSR2 or later, or Windows NT 4 or later, the GetDiskFreeSpaceEx function can be used to get a 64-bit value for the amount of free space available for a given path. The problem is what to do with that value, neither the INTEGER or NUMBER type can support the maximum that could be returned in a 64-bit value. One easy trick is to scale the value if it is too large to fit into a NUMBER. That is, convert it from Bytes to either Kilobytes or to Megabytes, depending on what will fit.

The source code included with this article includes only a few important parts to do the job. (The full DISKFREE.PFX program can be found on the Download page of the Powerflex web site. This first thing to look at is the iFSYSDiskSpace function (named this way because it returns an INTEGER - the 'i', and because it is part of a group of file system functions - the 'FSYS'). This function is the one that is intended to be used in other code, and would be the one exported if it were included in a module. It glues together all of the other functions that will be discussed in this article. Its definition:

function iFSYSDiskSpace string sDrive 1;
string sUnits byref ;
number nQuotaFree byref ;
number nQuotaSize byref ;
number nAllFree byref ;
returns integer

Purpose: This function retrieves information about the amount of space available for a given drive. It uses a Windows API function call that is available only in Microsoft Windows versions equal or later than Windows 95 OSR2 or Windows NT 4.

Parameters:

(in) sDrive STRING, maximum length 1. The drive letter to retrieve information about.

(in/out) sUnits STRING, byref. As an input this value represents the type of units that should be returned for the output values. However, if the given unit is too small to allow any one of the return value to fit into a NUMBER type, the output values will be scaled and the value of sUnits will be changed to match the units that are actually used for the output values. Valid values for sUnits are symbolically defined in the source code and are:

FSYS_UNITS_BYTES Output values are in bytes.
FSYS_UNITS_KILOBYTES Output values are in Kilobytes.
FSYS_UNITS_MEGABYTES Output values are in Megabytes.

If the input value of sUnits is not provided, a value of FSYS_UNITS_BYTES is assumed.

( out) nQuoteFree NUMBER, byref. The amount of free space on the specified drive that is available to the current user, in sUnits.

(out) nQuoteSize NUMBER, byref. The total amount of space on the specified drive that is available to the current user, in sUnits. (This includes free and used amounts.)

(out) nAllFree NUMBER, byref. The total amount of free space on the specified drive, in sUnits.

Return Value: INTEGER. If there was no error calling the Windows API function, the return value is zero (0). Otherwise the value is the Windows API LastError value. The message associated with this error code can be retrieved with the sWinLastErrorMessage function.

The iFSYSDiskSpace function first uses the iWinGetDiskFreeSpaceEx function, which is a wrapper and does little more then access the Windows API GetDiskFreeSpaceEx function. The Windows Platform SDK definition for this function is shown in the box below.

Note that the PULARGE_INTEGER type is a pointer to one of those C language things that can change depending on the C compiler used. This needs to be sorted out for use in PFXplus code. It basically represents a 64-bit signed integer, but for 32-bit use, can be split into High and Low 32-bit values. From PFXplus, a pointer to a two element INTEGER array works perfectly since the Low value ends up in the first element and the High value in the second. See the iWinGetDiskFreeSpaceEx function in the source code to see how this is done.

Next the iFSYSDiskSpace function uses nConvert64bBytes to convert the three High and Low values into the three NUMBER type output values. It may do this twice if any of the output values required scaling. The nConvert64bBytes function works by first splitting the High and Low values again from two 32-bits values into four 16-bit values. This removes the need to deal with the sign bit. Then the High values are checked to see if the result will be able to fit into a NUMBER type. For programming simplicity this is done with only one of the 16-bit values at a time, so the output value may not actually reach the absolute maximum value for a NUMBER before it is scaled.

BOOL GetDiskFreeSpaceEX {
LPCTSTR lpDirectoryName, // directory name
PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller
PULARGE_INTEGER lpTotalNumberOfBytes, // bytes on disk
PULARGE_INTEGER lpTotalNumberOfFreeBytes // free bytes on disk};}

For example, to determine if the final value should be converted to Megabytes, the high 16 bits of the High 32-bit value (HH) is checked. If it is greater than 362 then Megabytes are used. This is because somewhere between HH values of 362 and 363, the final value will be to big to express as Kilobytes using a NUMBER type. A value of greater than 362 for HH means that the final value is at least 97,173,635,072 Kilobytes and will be converted to Megabytes even though it is not quite at the 99,999,999,999 maximum value of a NUMBER.

Note that the nConvert64bBytes function does not convert to units above Megabytes. That is not needed because the maximum 64-bit value (about 17.5 trillion Megabytes) will fit into a NUMBER type when converted to Megabytes.

The last piece of code to look at is the sWinLastErrorMessage function. If an error is encountered calling the Window API function, iFSYSDiskSpace calls the WinLastError function that can be found in the WINCALLS module, and returns the value of the LastError. This is a Windows error code and not a PFXplus error code, so sWinLastErrorMessage must be used to get the correct error message. That function is defined:

function sWinLastErrorMessage ;
integer iErrCode ;
indicator bIncludeCode
returns string

Purpose: This function retrieves a string message from the operating system for the given error code, or for the last error.

Parameters:

(in) iErrorCode INTEGER. The error code to retrieve the message for. If this value is zero, the WinGetLastError function will be used to get the Windows LastError value. Note that since many operations can set the LastError value the function should only be used to get the LastError immediately after the place where LastError could have been set.

(in) bIncludeCode INDICATOR. If TRUE, the value of the error code will be appended to the end of the resulting message string. Return Value: STRING. The return value is the error message string returned from Windows for the given error code.

The iFSYSDiskSpace function can be used where ever you need to check disk space. I expect I will only have to rewrite it once more in my career. Keep watching for an update in an upcoming issue of POWERlines in about the year 2050. In the mean time, feel free to download and use the DISKFREE.PFX source code. Please submit any questions to the PFX Developers Mailing List (if you haven't subscribed see mailing list, or to me directly at aschwartz@growbiz.com

Top of Page

Technical Tip No.42

The following code, submitted by Axel Druschel of Coverflex Software in Germany, overcomes the problem of the "$STRUCT$FIND_FILNO" procedure of STRUCT.PFI not releasing used filenumbers when the addressed file buffer is closed.

integer p I
// skip the original initialisation; if non-zero file number then it may have already been created for us
isnew = true
if filno <> 0 begin
lasterr = 0
TRAP p = file(filno)\buffer
isnew = err
end
if not isnew exit
// we are going through all possible numbers, looking for a free one
for I from STRUCT_MINFILNO to STRUCT_MAXFILNO
lasterr = 0
TRAP p = file(I)\buffer
[err] break
loop
if err and lasterr == ERRNOTOPEN begin
err = false
lasterr = 0
filno = I
end
else error ERFILEOOR

Top of Page

Products Update


PFXweb Update

PFXweb beta development is continuing. Many of our customers have downloaded the beta version and are currently testing the software. The feedback we have received is very heartening and has included comments that PFXweb is a simple extension to PFXplus with excellent performance and that the components and tools required are minimal and often better to use than other Web platforms.

Comments such as these reinforce our confidence in PFXweb and its place in the next generation of Internet processing. If you would like to be a part of the PFXweb development then you can download the beta version from our website.. Phone (+61 3 9888 5833) or email us for details. u

New end user PFXbrowse in beta testing

PFXbrowse is a very powerful yet easy-to-use tool for displaying the contents of Powerflex and compatible data files. It also offers editing, find and replacement capabilities. Developers have always found PFXbrowse extremely useful but they have been reluctant to provide it to their end users because of its powerful editing functions which through misuse could result in serious data corruption.

Therefore, we have developed End-User PFXbrowse which while containing all the file display capabilities of PFXbrowse it does not allow editing of the data, thus making it safe to distribute to end users. If you are interested in being involved in the beta testing of End-User PFXbrowse contact us by phone (+61 3 9888 5833) or email (pfxsales@pfxcorp.com) for details of how to download the beta version from our web site.

Top of Page

Current Versions of Powerflex Release Software

PFXplus Developer's Kit 16/32-bit 4.23
PFXplus Developer's Kit 32-bit/SQL 5.0
PFXplus Runtimes 2.63 to 5.0
PFXplus Unixware 5.0
PFXplus SCO 4.30
PFXplus Linux 4.41
PFX C-lib MSDOS—DOS-386 4.20
PFX C-lib for Windows 5.0
PFX C-lib for Windows with MS SQL 5.0
PFX C-lib for SCO Unix/Linux 4.41
PFXsort for DOS-386, Win32/SQL 5.0
PFXsort for Unixware 5.0
PFXsort SCO Unix/linux 4.41
PFXbrowse 32-bit with Btrieve 5.0
PFXbrowse 32-bit for Windows 5.0
PFXbrowse Linux 4.41
PFXbrowse SCO Unix 2.10
PFXodbc 32-bit for WIndows 5.0
PFXcrystal 32-bit for Windows 5.0

For further information contact Powerflex Corporation or your local dealer.

Top of Page