4

The LA Fox Developer Newsletter
January 1998
Hot Tip...
Easy Way for Read/Write
of .ini Files
To access and change ini files you can use low-level file 10 and there are probably other such ways, but one of the eaiest ways to get and write data to .ini files is to use windows API calls. GetProfileSection, GetProflleString, WriteProfileString. Here is a sample use of these functions:

declare GetProfileString in win32api string,string,string, string @,integer
declare WriteProfileString in win32api string,string,string declare GetProfileSection in win32api string,string @,integer
**
the following example will read the available printer names
read the name of the default printer
**
and change the default printer to the first name on the list
**
NOTES : to change the active printer in VFP
--
it is much easier to get all the printer names using
**
APRINTERS() and than using SET PRINTER TO NAME
**
windowprintername but the printer section is common
**
to most users and this way most ppl can see this example
work - this .ini file change of the default printer will not
**
affect win95 users since win95 uses the registry to store
--
this info. This change in the ini file will not take affect
--
until you either restart windows or issue a
**
SendMessage (another API call) to all active windows
with a change in ini file msg
[WM_WININICHANGE (=26)]

The first parameter s the section name, the second parameter is the buffer the last parameter is the length
*
of the buffer . don’t specify something bigger than the
**
space you allocated to the buffer or you’ll get the infamous
“error 6 tying to report error 6” error (which means “You managed to smear my memory - now what?”)

IcBuffer=space(1000)
=GetProfileSection(”PrinterPorts”,@lcBuffer,lOOO)

this will get single line from the ini file, in this case the default
**
printer name: the first param is Section name, the second is
**
the item name, the third parameter “stam” is a default string
**
to return if no such line exists. Again, the 4th and last para
**
meters are the buiffer and Its length.
lcDefaultPrinter=space(50)
=GetProfileString("windows","device","stam",@c,50)

lnTempl=atc(”,”,lcBuffer,3)-1 lnTemp2=arc(char(O),lcBuffer).1 IcNewPrinter=left(lcBuffer,llt(InTemp2>InTempl ,lnTempl ,lnTemp2) =WriteProfileString(”windows” ,“device”,lcNewPrinter)
VFP Codebook for Mere
Mortals Update
from Kevin McNiesh

Here is a list of the major changes included in the latest release of VFP Codebook for Mere Mortals. Each of these changes plus many more are listed in the “What’s New” document and Developers Guide that comes with the framework.

Integration with Stonefield Database Toolkit
In this release we have provided integration with Stonefield Database Toolkit. We have created a new “Stonefield” component class that you can add to your application object when you want to integrate with Stonefield Database Toolkit. This Stonefleld class is a subclass of our new Component class which will be used in the future to integrate with other 3rd Party Products.

Greater Flexibility
We have added a greater degree of flexibility to the framework by means of our new Abstract Factory. This new class opens up the framework by allowing you to specify the concrete class names of the major framework components. This makes it very easy to replace components in the framework with your own custom classes.

For example, if you would like to replace the Mere Mortals error handier with your own error handler class, you can simply specify the name of the alternate error handler class in our new “Classes” table and the framework will take care of the rest. If you are not familiar with the Abstract Factory pattern, check out the book Design Patterns: Elements of Reusable Object- Oriented Software by Gamma, Helm, Johnson & Vlissides.

New Business Rules Class
Introduced the concept of a business rules class that can be attached to a business object. Breaking out business rules from the business object allows you to subclass and specialize business rules. For example, your application may require different business rules for different users. User I may be allowed to override a customer’s credit limit up to $10,000 whereas User 2 may only be allowed an override of up to
$5,000.

The framework does not require that you use a separate business rules class, but offers the option where needed.
Support for External Class Libraries
Join
LA Fox
In VFP 5, a new “IN” clause was added to the SET CLASSLIB command which allows you to access class libraries in an .app or .exe file outside of your main application. We have added support for external class libraries in our Abstract Factorj metadata table. You can specify that the framework use a particular class in a specific .exe or .app file.
(Con't, page 6)
Page 4

4