low hanging fruit... ahem functions

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

low hanging fruit... ahem functions

Post by mainhatten »

Johan told me it was ok to "implement" such stuff when reading code and thinking of a vfp function with a different name. Therefore:

Code: Select all

LOCAL lcPathedFile AS STRING
lcPath = "d:xS"
lcPathedFile = lcPath + "RootPlay.dbf"
? JustExt(lcPathedFile)
? JustStem(lcPathedFile)
? JustPath(lcPathedFile)
? JustDisk(lcPathedFile)

LOCAL loEmp   
* LOCAL loEmp AS OBJECT  
* loEmp = createobject("custom")
*-- nope, not yet

? "Press Exit Key"
RETURN

FUNCTION ByRef(tnChange OUT INT) AS Boolean
	tnChange = IiF (tnChange = 42, -42, 42)
	RETURN .t.
	
FUNCTION JustDisk (tcURI AS STRING) AS STRING
	LOCAL lcDisk AS STRING
	LOCAL lcDummy AS STRING
	= _SplitPath(tcURI, OUT lcDisk, OUT lcDummy, OUT lcDummy, OUT lcDummy)
	RETURN lcDisk
	  
FUNCTION JustPath (tcURI AS STRING) AS STRING
	LOCAL lcPath AS STRING
	LOCAL lcDummy AS STRING
	= _SplitPath(tcURI, OUT lcDummy, OUT lcPath, OUT lcDummy, OUT lcDummy)
	RETURN lcPath
	  
FUNCTION JustStem (tcURI AS STRING) AS STRING
	LOCAL lcStem AS STRING
	LOCAL lcDummy AS STRING
	= _SplitPath(tcURI, OUT lcDummy, OUT lcDummy, OUT lcStem, OUT lcDummy)
	RETURN lcStem

FUNCTION JustExt (tcURI AS STRING) AS STRING
	LOCAL lcExt AS STRING
	LOCAL lcDummy AS STRING
	= _SplitPath(tcURI, OUT lcDummy, OUT lcDummy, OUT lcDummy, OUT lcExt)
	RETURN lcExt

OUT in Parameter declaration is not the vfp way - sadly, I find it safer and easier to read than @in calling line
You can expect some equally taxing Force...functions in a few H - already done, but want to look them over on empty strings and such pesky stuff when I return.

HTH
thomas
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

low hanging fruit... ahem functions

Post by robert »

Thomas,
This is Ok, but you're better of using the functions / static methods inside the System.IO.Path namespace, like
System.IO.Path.GetDirectory(), System.IO.Path.GetExtension() etc.
_SplitPath uses these internally, but why both getting the extension (inside _SplitPath) if you're in he JustPath() function and only interested in the path.
The most difficult part in functions like these is to check what VFP does with erroneous input (like non existing files), and then decide if you want to do the same or not.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply