6 |
The LA Fox Developer Newsletter
|
October 1999
|
Q. I would like to add the button ‘Dial’ to my VFP grid with names and telephone numbers. After pressing the dial-button my modem should dial the number.
Al. If you are working on NT or Win95 you can use MSCOMM32.OCX that ships with VFP.
A2.
MSCOMM32.OCX only installs if your running Win95 or NT, not on Windows 3.1. If so, try this routine
using
the Window API. It works well under 3.1, pretty stable on 95 & NT. You’ll need to provide the parameters starting with THISFORM.
SET LIBRARY TO ‘FOXTOOLS.FLL’
ThisForm.CallNumber
M.Output
=
“ATDT”
+
ThisForm.CallNumber
+
PAM
+
CHR(13)
LOCAL Iccomport, lcdstring, Inport,
Iccomport
=
LEFT(THISFORM.ComPort,4)
Icdstring
=
m.output
OPENCOMM
=
REGFN(”OPENCOMM”,’CIl”,”l”,’USER.EXE’)
WRITECOMM
=
REGFN(’WRITECOMM’,’ICI’,’I’,USER.EXE’)
CLOSECOMM
=
REGFN(’CLOSECOMM’,’I’,’I’,’USER.EXE’)
open comm port
LNPORT
=
CALLFN(OPENCOMM,LCCOMPORT,1 00,100)
x
=
SECONDS()
DO WHILE SECONDSO
.
X <1
ENDDO
send string to modem
=CALLFN(WRITECOMM,LNPORT,LCDSTRING,LEN(LCDSTRING))
mTlmø
=
SEC.OP4DS()
DO While INKEY(”HM”) =0 AND SECONDSO
-
mTime <15
ENDDO
hang up modem M.Output
=
PATHOAMP
+
CHR(13) =CALLFN(WRITECOMM,LNPORT,LCDSTRING,LEN(LCDSTRING))
=CALLFN(CLOSECOMM,LNPORT)
x=SECONDS()
DOWHILESECONDSQ-X<2
ENDDO
RELEASE LIBRARY ‘FOXTOOLS’
(Ed Vanduyne, CIS ID: 75740,3071)
|
Endif
Q. What is the scope of an Include file?
Al.
When
you include a file in
a form using the Form/Include File menu item, all objects of the form have access to the contents. If you explicitly #include it in a method, only that method has access to it. In the class designer, the same rules apply. But you don’t have an easy way to have VFP include the same file in all classes stored in the classlib, it has to be specified on a class by class basis. No you don’t “inherit” include file contents. For a subclass you need to do is create a .h
file
for the subclass and then #include the parentclass’ .h
file
first and then add the #deflnes for the subclass. Something along the lines:
create class inc1 of inctest as custom
#define x I
create class incla of inctest as inc1 from inctest
#include incl.h
#define y 2
otherwise
inc1 a would not be able to use the #deflned x item.
It’s far from perfect, if the parentclass include filename changes the subclasses get broken, but it’s the
only way you can do it.
What I generally do with
classlibs is create a single
ClassLibName.h file and
every class stored in that classlib that needs an include file puts it’s contents in the single file. For application level stuff I create a single AppName.h file and include that on all the forms and prgs. And AppName.h #in
cludes any necessary .h files for the classlibs plus the app specific stuff.
(David
Frankenbach, CIS ID: 72147,2635)
|
Q. I am allowing the user to specify the name of a file. I am using PUTFILEO to
allow the user to enter the name, but when
they select a file that always exists, I always get a warning
about overwriting the
file. This happens no matter the setting of
SET SAFETY. Is
there an option?
Al. PutFile() invokes the standard windows Save Dialog. One
way around this is to use the common dialog OCX control. By placing the OCX control on a form, you can invoke the ShowSave() Method of the control. If you elect to choose a file that already exists, a dialog *wiIl not* appear. Once you have
made a file selection, this will update the FileName
Property of the OCX control:
ThisForm.OleControll .ShowSave()
If NOT Empty(ThisForm.OleControll.Filename)
|
Q. How can I implement an automatically incrementing primary key?
A. The most foolproof way I can find, and I’ve tried many, is to use a “system” table that stores the most-recently incremented number for each field. I have a GetPKey() function that will lock the record in the system table, increment the number, unlock
the record and return the number. If
I wanted to, GetPKey() could be used as the default value for the field in the database. I
choose not to do so for many reasons, but that is the simplest way to “autonumber” in VFP, IMHO. It would be nice
if
this were a built-in feature of the VFP engine as there are many drawbacks to the “roll your own” techniques required now. For example, functions for default values don’t
work
via ODBC.
|
Page 6
|
6 |