Options

How to use/initialize Dotnet Int32 type?

Slawek_GuzekSlawek_Guzek Member Posts: 1,690
Hi All,

I'd like to use standard .NET Int32 type to convert integer into hex representation (Int32.ToString('X4'))

Trouble is I cannot initialize in in C/AL?

If I create a variable of type DotNet System.Int32.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' I cannot initialize it in CAL. The line:
DotNetInt := DotNetInt.Int32;
gives an error : Assignment is not allowed for this variable.

Can I use Int32 type at all ?

Any other simple method to convert an int into hex ?

Slawek
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03

Best Answers

  • Options
    okioki Member Posts: 46
    Answer ✓
    Hi Slawek,

    you're right, impossible to work with Int32 or Int64. But you can work around it:

    Use an IntPtr: IntP DotNet System.IntPtr.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    IntP := IntP.IntPtr(1234);
    MESSAGE('Dec-Value='+IntP.ToString+', Hex-Value='+IntP.ToString('X4'));

    Also
    IntP := IntP.IntPtr(CAL_Int);
    works.

    Oli


Answers

  • Options
    DolshaDolsha Member Posts: 41
    If I understand correctly we dont need initialize variables in CAL.
    Constructor of Int32 in CAL: static [int Int32 :=] Int32();
  • Options
    okioki Member Posts: 46
    Answer ✓
    Hi Slawek,

    you're right, impossible to work with Int32 or Int64. But you can work around it:

    Use an IntPtr: IntP DotNet System.IntPtr.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    IntP := IntP.IntPtr(1234);
    MESSAGE('Dec-Value='+IntP.ToString+', Hex-Value='+IntP.ToString('X4'));

    Also
    IntP := IntP.IntPtr(CAL_Int);
    works.

    Oli


  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Thanks oki & lynge,

    lynge, a side note: your solution is not exact equivalent of int32.ToString('X4')). int32.ToString('X4')) gives you 4 character long hex string, while yours not.


    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.