Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

How to allow for functions to return String or Binary results 01 Nov 2020 18:09 #16459

  • atlopes
  • atlopes's Avatar
  • Topic Author


  • Posts: 84
  • 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
    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 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.
    ? 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

    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?

    Please Log in or Create an account to join the conversation.

    How to allow for functions to return String or Binary results 01 Nov 2020 21:10 #16460

    • robert
    • robert's Avatar


  • Posts: 3446
  • Antonio,
    I think I have forgotten to implement the implicit converter from Usual to Binary.
    Sorry about that.
    You can add this binary inside the usual to another binary and/or to a string. That works.
    But to retrieve the value as binary is not possible without "special tricks" at this moment.
    The only thing that you can do now is to add an extra cast:

    LOCAL binValue as Binary
    binValue := Binary{ (byte[] ) (OBJECT) usualValue}

    Of course I will add the implicit converter in the next build.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.

    How to allow for functions to return String or Binary results 02 Nov 2020 09:30 #16467

    • atlopes
    • atlopes's Avatar
    • Topic Author


  • Posts: 84
  • Robert, thank you.

    I'll try to use the workaround in current development & testing.

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1