Let's write the EVL() function for X#...
Posted: Thu May 07, 2020 11:46 pm
Hey all you VFP devs - Let's help the X# Dev Team spend their time working on really important stuff, while we write a few missing Runtime functions. I'm not expert at this X# stuff yet, but it doesn't have our beloved EVL() function, so I started poking away at one that seems to work well so far. If we get something that works in our testing, maybe X# Dev Team will include it in one of the upcoming releases.
I've two things so far: an actual EVL() function, and another TextEVL() function which makes multiple calls to EVL() with various data types. I've only hit the Int, String, and Logical data types so far, but maybe someone else can join me in getting this completes. Let's see what we can do!
Test function:
I've two things so far: an actual EVL() function, and another TextEVL() function which makes multiple calls to EVL() with various data types. I've only hit the Int, String, and Logical data types so far, but maybe someone else can join me in getting this completes. Let's see what we can do!
Code: Select all
// Early development of FoxPro EVL() Function by Matt Slay.
// Dear community - please help my finish this with any missing data types or
// even determine if there is a better way to implement this Function for X# Runtime.
// Discuss on this X# forum thread: https://www.xsharp.eu/forum/public-vfp/1923-let-s-write-the-evl-function-for-x
Function Evl(uValue, uReturnValue)
Var dataType = ValType(uValue) // Using native X# function call here.
Do Case
Case dataType = "C"
If Alltrim(uValue) == ""
Return uReturnValue
Else
Return uValue
Endif
Case dataType = "N"
If uValue = 0
Return uReturnValue
Else
Return uValue
Endif
Case dataType = "L"
If uValue
Return .t.
Else
Return uReturnValue
EndIf
End Case
End Function
Test function:
Code: Select all
*-- This function tests the EVL() function
Function TestEvl() As Logic
Local varIntZero, varIntNonZero
Local varDecimalZero, varDecimalNonZero
Local varEmptyString, VarNotEmptyString
Local varDate
Local varDateTime
Local varObject
Local varNull
Local lPassed
lPassed = .t.
varIntZero = 0
VarIntNonZero = 1
// Integer 0
If Evl(varIntZero, 1) = 1
? "Evl() on integer Zero Passed."
Else
? "Evl() on a integer 0."
lPassed = .f.
Endif
// Non-zer Integer
If Evl(varIntNonZero, 0) = 1
? "Evl() on a Non-zero Integer Passed."
Else
? "Evl() on a Non-zero Integer FAILED!!!"
lPassed = .f.
Endif
// Empty String
If Evl("", 1) = 1
? "Evl() on empty String Passed."
Else
? "Evl() on empty String FAILED !!!"
lPassed = .f.
Endif
// Non-Empty String
If Evl("Not_Empty_String", 1) = "Not_Empty_String"
? "Evl() on Non-Empty String Passed."
Else
? "Evl() on empty String FAILED !!!"
lPassed = .f.
Endif
// Logical False
If Evl(.f., 1) = 1
? "Evl() on logical .F. Passed."
Else
? "Evl() on logical .F. FAILED !!!"
lPassed = .f.
Endif
// Logical True
If Evl(.t., 1) = .t.
? "Evl() on logical .T. Passed."
Else
? "Evl() on logical .T. FAILED !!!"
lPassed = .f.
Endif
Var oObject = Empty{}
AddProperty(oObject, "TestProperty", 1)
// Test by passing a dynamically added property on Empty object
If Evl(oObject.TestProperty, 2) = 1
? "Evl() on Dynamically added property Passed."
Else
? "Evl() on Dynamically added property Failed !!!"
lPassed = .f.
Endif
// ToDo: Test Date & Empty Date
// Todo: Test Null
// ToDo: Test DateTime & Empty DateTime
// ToDo: Figure out all the other data types that need to be tested.
Wait
Return lPassed
End Function