10.2B04. Trying to find a way of adding an array to a ComboBoxEdit control. The easy way doesn't work
given this class
using Progress.Lang.*.
routine-level on error undo, throw.
class dotr.MyClass :
def public static property p1 as character init "p1" no-undo get . private set.
def public static property p2 as character init "p2" no-undo get . private set.def public static property Array1 as System.Object extent 2 no-undo get . private set.
Array1[2] = dotr.MyClass:p2.
constructor static MyClass ( ):
assign Array1[1] = dotr.MyClass:p1end constructor.
end class./* end of class */
I am trying to add Array1 to a comboBoxEdit control
this-object:comboBoxEdit1:Properties:Items:AddRange(dotr.MyClass:Array1).
this fails with the message
"System.ArgumentException:Invalid argument type (15581)"
Invalid argument type (15581)
The argument passed was not a type that can be converted to a .NET type.
however, if I use the following:
def var a1 as System.Object extent 2 no-undo.
a1 = dotr.MyClass.Array1.this-object:comboBoxEdit1:Properties:Items:AddRange(a1).
this works just fine.
What gives ? a1 and Array1 are both of type Sysem.Object. They are both an array of 2.
Does it help if you'd define your property as a .NET Array:
DEFINE STATIC PROPERTY Array1 AS "System.Object[]" NO-UNDO .
That is what I noticed too. Progress cannot convert some types if they are refrenced as properties. I guess, it's a quirk that just have to be experienced. I wish Progress had this documented though.
In the same line;
RUN .... IN someObject:ProcHandle - it will complain about someObject:ProcHandle.
Assign someObject:procHandle to another vaariable
RUN ... IN procHandle - this works
jquerijero wrote:
That is what I noticed too. Progress cannot convert some types if they are refrenced as properties. I guess, it's a quirk that just have to be experienced. I wish Progress had this documented though.
In the same line;
RUN .... IN someObject:ProcHandle - it will complain about someObject:ProcHandle.
Assign someObject:procHandle to another vaariable
RUN ... IN procHandle - this works
Yes. And
RUN .... IN someObject:ProcHandle() works as well!
The original case - not being able to do this:
this-object:comboBoxEdit1:Properties:Items:AddRange(dotr.MyClass:Array1).
is not a problem because you are referencing a property (dotr.MyClass:Array1). It is because in general we do not automatically convert an ABL array to a .NET object (specifically System.Object[], which is what is required here). The only time we automatically convert an ABL array to a .NET array is in an assignment statement where the left-hand side is System.Object, as you showed:
def var a1 as System.Object extent 2 no-undo.
a1 = dotr.MyClass.Array1.
This is referred to as boxing, and I believe the documentation does state this. But I agree, it's confusing.
The other problem, that the compiler complains about this:
RUN .... IN someObject:ProcHandle .
IS because you are using a property. This is on our roadmap - to complete the implementation of properties so that they can be used everywhere that a variable is used.
stern wrote:
The other problem, that the compiler complains about this:
RUN .... IN someObject:ProcHandle .
IS because you are using a property. This is on our roadmap - to complete the implementation of properties so that they can be used everywhere that a variable is used.
Thanks! Looking forward to that.
-peter
This particular issue: RUN ... IN someObject:ProcHandle has been addressed in 11.0.
bleicher wrote:
This particular issue: RUN ... IN someObject:ProcHandle has been addressed in 11.0.
Right, I'm officially confused again (don't worry, it happens often ..)
take this class:
class demo.ClassA :
def public property SomeHandle as handle no-undo get . private set .
constructor ClassA(p_Handle as handle):
SomeHandle = p_Handle.
end constructor.
end class.
and this procedure:
def var a as demo.classA.
a = new demo.classA(this-procedure).
run "test" in a:SomeHandle .
procedure test:
message proversion "foo" view-as alert-box.
end procedure.
Are you saying that this is fixed in 11 ?
So .... how is that it works in 10.2B ...
SP05, mind ....
I was using a slightly modified example.
The following code does not compile in 10.2B05. The compiler generates error: "Could not locate element 'SomeHandle' in class 'demo.classA'. (12927).
def var a as demo.classA.
DEF VARIABLE mych AS CHAR.
a = new demo.classA(this-procedure).
run "test" in a:SomeHandle (3, OUTPUT mych).
procedure test:
DEFINE INPUT PARAMETER i AS INTEGER.
DEFINE OUTPUT PARAMETER ch AS CHAR.
ch = STRING(i).
message proversion "foo" view-as alert-box.
end procedure.
In 11.0, this code compiles and executes properly. The issue was how the parameters on the RUN statement were handled. I believe that if you remove the parameters on the RUN statement, the compiler in 10.2B05 handles this code correctly.
bleicher wrote:
I was using a slightly modified example.
The following code does not compile in 10.2B05. The compiler generates error: "Could not locate element 'SomeHandle' in class 'demo.classA'. (12927).
def var a as demo.classA.
DEF VARIABLE mych AS CHAR.a = new demo.classA(this-procedure).
run "test" in a:SomeHandle (3, OUTPUT mych).
procedure test:
DEFINE INPUT PARAMETER i AS INTEGER.
DEFINE OUTPUT PARAMETER ch AS CHAR.ch = STRING(i).
message proversion "foo" view-as alert-box.
end procedure.In 11.0, this code compiles and executes properly. The issue was how the parameters on the RUN statement were handled. I believe that if you remove the parameters on the RUN statement, the compiler in 10.2B05 handles this code correctly.
I see your modified example, and raise you ..
def var a as demo.classA.
def var ch as char no-undo.
a = new demo.classA(this-procedure).
run "test" in (a:SomeHandle) (1,output ch).
procedure test:
def input parameter p_data as int no-undo.
def output parameter p_ch as char no-undo.
p_ch = string(p_Data).
message proversion "foo" p_Data p_ch view-as alert-box.
end procedure.
compiles and runs
You win!
As you noted, strategic use of parentheses, is a workaround for this issue and allows the compiler to do the right thing.