5 |
The LA Fox Developer Newsletter
Inserting/Retrieving
(Con’t from page 4)
cBuffer
=
&& Empty buffer right now
IReading = FALSE && We didn’t read the file successfully && If the resource file exists
if ( FILE( cResourceFile))
&& If the file we want to store exists
IF ( FILE( cResource))
&& If we successfully read the file
IReading = CopyFileToVar( cResource,@cBuffer IF ( IReading)
&& Insert the content in the DBF!
INSERT INTO ( cResourceFile)
VALUES ( UPPER( cKeyword)
UPPER( LEFT( cType,3)),;
IRetVaI = TRUE
USE
ENDIF
ENDIF
ENDIF
RETURN C IRetVaI
The Savebltmap() function becomes somewhat sImpler to code:
FUNCTION SaveBitmap( cResourceFile,cResource,cKeyword RETURN ( SaveFile( cResourceFile,cResource,cKeyword, “BMP”
The miracle of such implementation is that it is now also easy to codethe SaveWave() function:
RETURN ( SaveFile( cResourceFile,cResource,cKeyword, “WAV”
the SaveCursor() function
FUNCTION SaveCursor( cResourceFile,cResource,cKeyword RETURN ( SaveFile( cResourceFile,cResource,cKeyword, “BMP”
the Savelcon() function
FUNCTION Savel con( cResourceFile,cResource,cKeyword RETURN ( SaveFile( cResourceFile,cResource,cKeyword, “ICO”
or the SaveDBF() function
FUNCTION SaveDBF( cResourceFile,cResource,cKeyword RETURN ( SaveFile( cResourceFile,cResource,cKeyword, “DBF”
Here we are: saving a DBF in a DBF And what if this DBF has an associated memo file ? That peculiarity of DBF files makes it imperative to slightly adapt the SaveFile() function.
Linked Content
Although dozens of algorithms can be Chosen here, the one I
have retained to handle all particular cases in the SaveFile()
function itself is as follows:
|
April 1999
FUNCTION SaveFile( cResourceFile,cResource,cKeyword,cType LOCAL IRetVal && Logical return of the function
LOCAL cBuffer && Internal buffer
LOCAL IReadingBuf && Successful reading of the primary file?
LOCAL cLinked && Linked content
LOCAL cLinkedExt && Extension of the linked file
LOCAL cBaseFile && Filename without extension
IRetVal
=
FALSE && Function is not successful by default cBuffer
=
““
&& Empty buffer right now IReadingBuf
=
FALSE && We didn’t read the file successfully cLinked
=
““
&& Linked content
cLinkedExt
=
“.“
&& No linked extension by default
&& If the resource file exists
IF
(
FILE( cResourceFile))
&& If the file we want to store exists
IF
(
FILE( cResource))
&& If we successfully read the file
IReadingBuf
=
CopyFileToVar( cResource,@cBuffer) IF
(
IReadingBuf)
&& Handle special cases right here
cType
=
UPPER( LEFT( cType,3))
IF
(
cType
==
“BMP” .OR. cType
==
“DBF”)
IF(cType”BMP”)
ELSE
cLinkedExt
=
“.FPT”
ENDIF
ENDIF
&& Here, I’ll use FOCUS.FLL’s FIL_split() function Ill
cBaseFile
=
FIL_split( cResource,1
)
+;
FIL_split( cResource,2
)
+;
FIL_split( cResource,3)
&& If we found a Inked file
CopyFileToVar( cBaseFile
+
cLinkedExt,@cLinked)
INSERT INTO
(
cResourceFile)
VALUES
(
UPPER( cKeyword),.
clype
IRetVaI TRUE
USE
ENDIF
ENDIF
ENDIF
RETURN
(
IRetVal)
As one can see, I have been using FOCUS.FLL to be able to split a filename into its basic components: drive, directory, file, extension.
FOCUS.FLL is a dynamic linked library that
can
be used
in
Visual FoxPro 5.0 programs. It will be extended to be used from Visual Basic and MS-Access programs. It contains more or less 800 functions all divided into categories (each function is actually prefixed by a 3 letters Category and an underscore, for example STR_TiIlNullO, where STR stands for STRings).
FOCUS.FLL is used by more than 4000 developers in the world. Many of them play an incredible role in fine-tuning the library by reporting suggestions, anomalies, quirks, etc. FOCUS.FLL is not new: it exists since 1994 and has known a number of updates. It is available from CompuServe for 4 years now.
|
Page 5
|
5 |