Help translating C# - Forum - OpenEdge Development - Progress Community
 Forum

Help translating C#

  • Does anyone have an idea how to convert the C# code below? In C# the (int)OPOS_Constants.OPOS_SUCCESS returns a 0 but if I try that in the ABL it returns a 1009. The OPOS_Constants class declares all the OPOS Constants as enumerations. I have used EnumHelper in the past to compare to enum but how would I use to compare to an integer?

    Sample C# Code

    int nRC;

    // Open the printer.

    nRC = Printer.Open("Printer");

    // If succeeded, then claim.

    if (nRC == (int)OPOS_Constants.OPOS_SUCCESS)

    Sample ABL Code

    DEF VAR iReturnCode AS INTEGER NO-UNDO.

    iReturnCode = oPrinter:

    /* If succeeded, then claim. */

    IF iReturnCode = INTEGER (OPOS_Constants:OPOS_SUCCESS) THEN

    Open("Printer").
  • 1009 sounds a lot like the ABL is interpreting it an a pseudo widget handle.

    IF iReturnCode = INTEGER (OPOS_Constants:OPOS_SUCCESS) THEN

    Try INTEGER (UNBOX (OPOS_Constants:OPOS_SUCCESS))

    or

    UNBOX (OPOS_Constants:OPOS_SUCCESS)

  • I did try that but progress does not like it. I get a syntax error:

    The argument to UNBOX must be a class of type System.Object or be a .NET array object. (14690)

    Roger Blanchard

  • I've worked with the Microsoft POS SDK before, but I never needs that class.

    How does that property/enum look like in the Class browser? Or do you have a Microsoft reference at hand? Some enum members may actually have a value.

  • From the Class Browser it has the following info.

    PUBLIC VARIABLE OPOS_SUCCESS AS POS.Devices.OPOS_Constants

    Member of POS.Devices.OPOS_Constants

    Summary:

    For the OPOS_Constants class.

    CLASS OPOS_Constants FINAL :

    Member of POS.Devices

    Inherits System.Enum

    Implements System.IComparable, System.IFormattable, System.IConvertible

    Summary:

    ABL Syntax:

    USING

    USING POS.Devices.OPOS_Constants.

    DEFINE VARIABLE class1 AS CLASS OPOS_Constants.

    class1 = NEW OPOS_Constants().

    DEFINE

    DEFINE VARIABLE class1 AS CLASS POS.Devices.OPOS_Constants.

    class1 = NEW POS.Devices.OPOS_Constants().

    Roger Blanchard

  • If you look at the IConvertible interface which OPOS_Constants implements it has conversion methods like ToInt( ). Try

    iReturnCode = oPrinter:Open("Printer").

    /* If succeeded, then claim. */

    IF iReturnCode = OPOS_Constants:OPOS_SUCCESS:ToInt( ) THEN ...

    I did not try it but I think it should do what you are looking for.

    FYI: When you called INTEGER (OPOS_Constants:OPOS_SUCCESS)you are asking for an integer representation of the objRef. Under the covers the objRef calls ToString( ) to by default returns a pointer value for the object.

    -Shelley

  • Well I tried OPOS_Constants:OPOS_SUCCESS:ToInt() and received the syntax error:

    Could not locate element ‘ToInt’ in class ‘POS.Devices.OPOS_Constants’. (12927)

    Roger Blanchard

  • My mistake. The method is Actually ToInt32( ). You can look at System.IConvertible in the Class Browser for the methods on the interface.

    -Shelley

  • I reviewed the Class Browser for System.IConvertible and you would think that would work. However, I get the same error and when I hit CTRL+SPACE after OPOS_Constants:OPOS_SUCCESS: I do not see ToInt32 listed.

    Roger Blanchard

  • Actually it's the OPOS_Constants class that implements IConvertible.

    -Shelley

  • The code below works for me in 10.2B04 - it's pretty close to what Shelley suggested.

    using POS.Devices.OPOS_Constants.

    DEF VAR iReturnCode AS INTEGER NO-UNDO.
    DEF VAR iSuccessEnumValue as integer.

    iSuccessEnumValue = System.Convert:ToInt32(OPOS_Constants:OPOS_SUCCESS).

    iReturnCode = Printer:Open("myPrinter").

    /* If succeeded, then claim. */
    IF iReturnCode eq iSuccessEnumValue then
        Open("Printer").

    Well, the Enum bits anyway. I couldn't get the Printer bit to compile, but I figured you'd already got that working.

    Got lots of help from http://msdn.microsoft.com/en-us/library/system.enum.aspx and the DLLs from http://monroecs.com/posfordotnet/opos_dotnet.htm .

    -- peter

  • Thanks Shelley!!

    Roger Blanchard

  • It was actually Peter Judge that figured it out.

    Thanks to Peter!!

  • Thanks for the sample Peter, I now have it working. I do have a follow up question though. In your sample you converted the OPOS_SUCCESS at the top of the program using:

    iSuccessEnumValue = System.Convert:ToInt32(OPOS_Constants:OPOS_SUCCESS).

    Is there a benefit to that over what I have below? The reason I ask is there are hundreds of CONSTANTS and it would be easier to do as I did instead of having to convert each one.

    iReturnCode = oPrinter:Open(THIS-OBJECT:PrinterName).

    IF iReturnCode = System.Convert:ToInt32(OPOS_Constants:OPOS_SUCCESS) THEN

    Roger Blanchard

  • Mike,

    Thanks for the help as well.

    Roger Blanchard