How to display .NET Extent Class Property? - Forum - OpenEdge General - Progress Community

How to display .NET Extent Class Property?

 Forum

How to display .NET Extent Class Property?

This question is answered

I am trying to convert a complex .NET code to openedge.   How do you access a Class Property of a .NET extent class?

For Example: System.Strings Class has LENGTH property.  what is the syntax to display LENGTH property?


DEFINE VARIABLE someStrings AS  CLASS "System.String[]" NO-UNDO.

someStrings = CAST (System.Array:CreateInstance (Progress.Util.TypeHelper:GetType ("System.String"), 3),                   "System.String[]") .  

someStrings:SetValue ("Test", 0) .

MESSAGE VALID-OBJECT (someStrings) SKIP
        someStrings:GetValue (0)
    VIEW-AS ALERT-BOX INFO BUTTONS OK.

My class is very complex.  I have just listed a STRINGS class as an example.

Thanks for your help. 

Verified Answer
  • First, to answer your question, an array in .NET is just a class - as you've already demonstrated.  It has methods and properties.  Length is one of the properties.  So just access it (someStrings;Length).

    Also, you don't need to use TypeHelper any more to create the object.  You had to do that when we first introduced this, but no longer.  I don't remember what version that changed in, but it's been a while now.  So the full example could be:

    DEFINE VARIABLE someStrings AS  CLASS "System.String[]" NO-UNDO.

    someStrings = NEW  "System.String[]"(3).

    someStrings:SetValue ("Test", 0) .

    MESSAGE VALID-OBJECT (someStrings) SKIP

           someStrings:GetValue(0)  SKIP

           someStrings:LENGTH

       VIEW-AS ALERT-BOX INFO BUTTONS OK.

  • I just posted an answer before I saw this real example.  It seems to have gotten lost.  But no matter, I will answer the real question.

    1. I don't know why you are creating the resultArray (which i presume should be the variable "results"!).  That will be created by .NET and returned to you from the readFile() method.  You are creating it and then it is just getting replaced.  

    2. For future reference (since now you don't need it here), you don't need to use TypeHelper anymore to create a .NET array instance.  You had to when we first introduced this, but no more (don't remember what version that changed in).  Now you could do:

      results = NEW "ScanResult[]"(3).

    3. What is scanCode?  You seem to be missing some things here.  I presume you meant results[0]:CodeText.   As you've already shown, you can't just use the array syntax [0] on a .NET array.  You need to use GetValue.  In theory, you would do:

      results:GetValue(0):CodeText.

    But GetValue returns a System.Object, so this would have to be CAST to access the CodeText property.  Probably better to split it into 2 statements.

      result = CAST(results:GetValue(0), <name of result object>.

      myCodeText = results:CodeText.  

All Replies
  • Here is my simplified . Net Code which I am trying to convert to ABL

    using propsoft.fingerscancode;

    scanReader reader = new scanReader();

    try

    {

       ScanResult[] results = reader.ReadFile("<file-name>");

       for (int i = 0; i < results.Length; ++i)

       {

           ScanResult scancode = results[i];      <---  This is where I am strugling

           MessageBox.Show(scancode.codeText);  <--- How to access extent class property in ABL?  

       }

    }

    Here is my ABL attempt:  

    USING propsoft.fingerscancode.*.

    USING Progress.Util.* FROM ASSEMBLY.

    DEFINE VARIABLE reader  AS  CLASS scanReader.

    DEFINE VARIABLE results AS  CLASS "scanResult[]" .

    resultArray    =  CAST(System.Array:CreateInstance (Progress.Util.TypeHelper:GetType("propsoft.fingerscancode.scanResult"), 3),"ScanResult[]").

    reader = NEW scanReader().

    results = reader:readFile("<file-name>").

    /** how do I access property 'CodeText' from results .NET array? **/

    MESSAGE scanCode[0]:CodeText VIEW-AS ALERT-BOX.  /** Gives me syntax error **/

    Thanks - Brady

  • First, to answer your question, an array in .NET is just a class - as you've already demonstrated.  It has methods and properties.  Length is one of the properties.  So just access it (someStrings;Length).

    Also, you don't need to use TypeHelper any more to create the object.  You had to do that when we first introduced this, but no longer.  I don't remember what version that changed in, but it's been a while now.  So the full example could be:

    DEFINE VARIABLE someStrings AS  CLASS "System.String[]" NO-UNDO.

    someStrings = NEW  "System.String[]"(3).

    someStrings:SetValue ("Test", 0) .

    MESSAGE VALID-OBJECT (someStrings) SKIP

           someStrings:GetValue(0)  SKIP

           someStrings:LENGTH

       VIEW-AS ALERT-BOX INFO BUTTONS OK.

  • I just posted an answer before I saw this real example.  It seems to have gotten lost.  But no matter, I will answer the real question.

    1. I don't know why you are creating the resultArray (which i presume should be the variable "results"!).  That will be created by .NET and returned to you from the readFile() method.  You are creating it and then it is just getting replaced.  

    2. For future reference (since now you don't need it here), you don't need to use TypeHelper anymore to create a .NET array instance.  You had to when we first introduced this, but no more (don't remember what version that changed in).  Now you could do:

      results = NEW "ScanResult[]"(3).

    3. What is scanCode?  You seem to be missing some things here.  I presume you meant results[0]:CodeText.   As you've already shown, you can't just use the array syntax [0] on a .NET array.  You need to use GetValue.  In theory, you would do:

      results:GetValue(0):CodeText.

    But GetValue returns a System.Object, so this would have to be CAST to access the CodeText property.  Probably better to split it into 2 statements.

      result = CAST(results:GetValue(0), <name of result object>.

      myCodeText = results:CodeText.  

  • >> result = CAST(results:GetValue(0), <name of result object>.

    Perfect. You are a life saver.    I am just starting out with .NET and I was struggling with the above syntax.  Thank You.  

  • /** Gives me syntax error **/
     
     
    Which one? I usually prefer to read error messages rather than guessing which error might be possible.
     
    Von: bharold41 [mailto:bounce-bharold41@community.progress.com]
    Gesendet: Montag, 20. November 2017 16:29
    An: TU.OE.General@community.progress.com
    Betreff: RE: [Technical Users - OE General] How to display .NET Extent Class Property?
     
    Update from Progress Community
     

    Here is my simplified . Net Code which I am trying to convert to ABL

    using propsoft.fingerscancode;

    scanReader reader = new scanReader();

    try

    {

       ScanResult[] results = reader.ReadFile("<file-name>");

       for (int i = 0; i < results.Length; ++i)

       {

           ScanResult scancode = results[i];      <---  This is where I am strugling

           MessageBox.Show(scancode.codeText);  <--- How to access extent class property in ABL?  

       }

    }

    Here is my ABL attempt:  

    USING propsoft.fingerscancode.*.

    USING Progress.Util.* FROM ASSEMBLY.

    DEFINE VARIABLE reader  AS  CLASS scanReader.

    DEFINE VARIABLE results AS  CLASS "scanResult[]" .

    resultArray    =  CAST(System.Array:CreateInstance (Progress.Util.TypeHelper:GetType("propsoft.fingerscancode.scanResult"), 3),"ScanResult[]").

    reader = NEW scanReader().

    results = reader:readFile("<file-name>").

    /** how do I access property 'CodeText' from results .NET array? **/

    MESSAGE scanCode[0]:CodeText VIEW-AS ALERT-BOX.  /** Gives me syntax error **/

    Thanks - Brady

    View online

     

    You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

    Flag this post as spam/abuse.

     

    Architect of the SmartComponent Library and WinKit

    Consultingwerk Ltd.