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.
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
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:CodeText. As you've already shown, you can't just use the array syntax  on a .NET array. You need to use GetValue. In theory, you would do:
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.
Here is my simplified . Net Code which I am trying to convert to ABL
scanReader reader = new scanReader();
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 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:CodeText VIEW-AS ALERT-BOX. /** Gives me syntax error **/
Thanks - Brady
>> 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.
You received this notification because you subscribed to the forum. To unsubscribe from only this thread,
post as spam/abuse.
Architect of the SmartComponent Library and WinKit