How to allow for functions to return String or Binary results
Posted: Sun Nov 01, 2020 5:09 pm
I'm trying to implement the VFP's STRCONV() function.
Depending on the arguments passed to the function, I want the result to be either of String or Binary type.
I declared the functions as
When the result is a String, as in the Single Byte to Base64 conversion, I can do whatever I need with the result and use it anywhere an expression is expected.
When the result is a Binary, as in Base64 to Single Byte conversion, there is not much I can do with the result except displaying it. If i try to use what's returned in some other context, an assignment into a Binary variable, for instance, a runtime error System.InvalidCastException pops up.
Is there is anything I'm missing in the interpretation of what the USUAL type is able to do? Or is it something still missing from the implementation of the Binary type?
Depending on the arguments passed to the function, I want the result to be either of String or Binary type.
I declared the functions as
Code: Select all
FUNCTION StrConv (Expression AS String, ConversionSetting AS Int, RegionalIdentifier AS Int, RegionalIDType AS Int) AS USUAL
...
FUNCTION StrConv (Expression AS Binary, ConversionSetting AS Int, RegionalIdentifier AS Int, RegionalIDType AS Int) AS USUAL
When the result is a Binary, as in Base64 to Single Byte conversion, there is not much I can do with the result except displaying it. If i try to use what's returned in some other context, an assignment into a Binary variable, for instance, a runtime error System.InvalidCastException pops up.
Code: Select all
? StrConv("Abcd", STRCNV_SB_BASE64) && displays QWJjZA==, which is good
? StrConv("QWJjZA==", STRCNV_BASE64_SB) && displays 0h41626364, which is also good
* but it seems that there is nothing else besides displaying that this returned value can do