Why does OLE/COM code domain error?
Forum rules
The FAQ is a read-only forum which is in general updated only by employees of Dyalog Ltd. It replaces the FAQ page which existed under http://www.dyalog.com. Rather than rejecting other posts to this forum, such posts will be put in a moderation queue, and moved to a more appropriate forum.
The FAQ is a read-only forum which is in general updated only by employees of Dyalog Ltd. It replaces the FAQ page which existed under http://www.dyalog.com. Rather than rejecting other posts to this forum, such posts will be put in a moderation queue, and moved to a more appropriate forum.
1 post
• Page 1 of 1
Why does OLE/COM code domain error?
Or, why does OLE/COM code written for a pre-11 Dyalog stop working when it did before?
Starting from v11, the default value for ⎕WX is 3. This improves behaviour in the interaction of Dyalog with COM and .Net objects.
The most common issue to encounter with older code when working under the new ⎕WX is this: character vectors supplied as arguments to external functions, which are defined as String parameters, must be enclosed. Strings are returned as enclosed character vectors.
External Object Behaviour
From Version 11.0, ⎕WX defaults to 3 which improves the behaviour of COM and .Net objects, but for backwards compatibility it is possible to select old or new behaviour using ⎕WX.
Old behaviour:
New behaviour
The actual behaviour of a COM or .Net object is now determined by its value of ⎕WX. If ⎕WX is 0 or 1, the old behaviour will apply. If ⎕WX is 3, the new behaviour will apply.
The behaviour of COM and .Net objects in existing applications will remain the same (because ⎕WX will be 0 or 1) but you may obtain the benefits of the new behaviour by setting ⎕WX to 3 at the appropriate level in your application. Then, everything below that (in the namespace hierarchy) will adopt the new behaviour.
Note that regardless of the value of ⎕WX, Dyalog will honour the Default Property of an external object thereby permitting the direct use of indexing on the object itself.
For example, if xl is an instance of the Excel.Application COM class, the following expression to obtain the contents of the first Sheet in the first Workbook will succeed, whatever the value of ⎕WX.
xl.Workbooks[1].Sheets[1].UsedRange.Value2
Note that it is the value of ⎕WX which the object acquired when it was created, rather than the current value of ⎕WX, which decide the behaviour.
Like other system variables, ⎕WX is inherited from the environment when a new namespace, class or instance is created. Classes inherit the value of ⎕WX when a class is edited or fixed, unless the class script explicitly sets a value for ⎕WX. In the case of .NET classes, ⎕WX is inherited when the class or namespace is loaded from a .NET assembly. For built-in (GUI) classes, each new instance inherits ⎕WX when it is created.
Examples
⎕WX←1
'XLW' ⎕WC 'OleClient' 'Excel.Application'
XLW.Workbooks.Add ⍬
XLW.ActiveWorkbook.Sheets.(Item 'Sheet2').Index
2
⎕WX←3
XL←⎕WC 'OleClient' (⊂'ClassName' 'Excel.Application')
XL.Workbooks.Add ⍬
XL.ActiveWorkbook.Sheets[⊂'Sheet2'].Index
2
Note that it is the value of ⎕WX in the object, and not in the calling environment, that decides the behaviour:
⎕wx←3
⎕using←''
System.DateTime.Parse⊂'2006-09-12'
12/09/2006 00:00:00
⎕wx←1
System.DateTime.Parse'2006-09-12'
LENGTH ERROR
System.DateTime.Parse'2006-09-12'
∧
System.DateTime.⎕WX←1
System.DateTime.Parse'2006-09-12'
12/09/2006 00:00:00
Note that, if we expunged the System.DateTime class instead of setting ⎕WX to 1, and repeated the expression, a new DateTime class would be created but it would inherit ⎕WX from its parent (System), where ⎕WX still has the value 3. Using .NET classes in an application where ⎕WX varies within a single APL namespace can therefore lead to unexpected results. It is recommended that applications only use more than one value for ⎕WX as a temporary measure during a conversion project.
Starting from v11, the default value for ⎕WX is 3. This improves behaviour in the interaction of Dyalog with COM and .Net objects.
The most common issue to encounter with older code when working under the new ⎕WX is this: character vectors supplied as arguments to external functions, which are defined as String parameters, must be enclosed. Strings are returned as enclosed character vectors.
External Object Behaviour
From Version 11.0, ⎕WX defaults to 3 which improves the behaviour of COM and .Net objects, but for backwards compatibility it is possible to select old or new behaviour using ⎕WX.
Old behaviour:
- Character vectors supplied as arguments to external functions, which are defined as String parameters, are automatically enclosed for you. Similarly, string results are automatically disclosed.
Properties that take parameters, such as the Item Property in a Collection, are treated as methods.
APL provides lists of the Properties, Methods and Events provided by a GUI object by exposing additional properties named PropList, MethodList and EventList.
New behaviour
- Character vectors supplied as arguments to external functions, which are defined as String parameters, must be enclosed. Strings are returned as enclosed character vectors.
Properties that take indices, such as the Item Property in a Collection, are honoured as Numbered or Keyed Properties and may be accessed by indexing.
PropList, MethodList and EventList are not exposed. Instead, the information is provided by ⎕NL ¯2,¯3 and ¯8 (but alphabetically sorted).
The actual behaviour of a COM or .Net object is now determined by its value of ⎕WX. If ⎕WX is 0 or 1, the old behaviour will apply. If ⎕WX is 3, the new behaviour will apply.
The behaviour of COM and .Net objects in existing applications will remain the same (because ⎕WX will be 0 or 1) but you may obtain the benefits of the new behaviour by setting ⎕WX to 3 at the appropriate level in your application. Then, everything below that (in the namespace hierarchy) will adopt the new behaviour.
Note that regardless of the value of ⎕WX, Dyalog will honour the Default Property of an external object thereby permitting the direct use of indexing on the object itself.
For example, if xl is an instance of the Excel.Application COM class, the following expression to obtain the contents of the first Sheet in the first Workbook will succeed, whatever the value of ⎕WX.
xl.Workbooks[1].Sheets[1].UsedRange.Value2
Note that it is the value of ⎕WX which the object acquired when it was created, rather than the current value of ⎕WX, which decide the behaviour.
Like other system variables, ⎕WX is inherited from the environment when a new namespace, class or instance is created. Classes inherit the value of ⎕WX when a class is edited or fixed, unless the class script explicitly sets a value for ⎕WX. In the case of .NET classes, ⎕WX is inherited when the class or namespace is loaded from a .NET assembly. For built-in (GUI) classes, each new instance inherits ⎕WX when it is created.
Examples
⎕WX←1
'XLW' ⎕WC 'OleClient' 'Excel.Application'
XLW.Workbooks.Add ⍬
XLW.ActiveWorkbook.Sheets.(Item 'Sheet2').Index
2
⎕WX←3
XL←⎕WC 'OleClient' (⊂'ClassName' 'Excel.Application')
XL.Workbooks.Add ⍬
XL.ActiveWorkbook.Sheets[⊂'Sheet2'].Index
2
Note that it is the value of ⎕WX in the object, and not in the calling environment, that decides the behaviour:
⎕wx←3
⎕using←''
System.DateTime.Parse⊂'2006-09-12'
12/09/2006 00:00:00
⎕wx←1
System.DateTime.Parse'2006-09-12'
LENGTH ERROR
System.DateTime.Parse'2006-09-12'
∧
System.DateTime.⎕WX←1
System.DateTime.Parse'2006-09-12'
12/09/2006 00:00:00
Note that, if we expunged the System.DateTime class instead of setting ⎕WX to 1, and repeated the expression, a new DateTime class would be created but it would inherit ⎕WX from its parent (System), where ⎕WX still has the value 3. Using .NET classes in an application where ⎕WX varies within a single APL namespace can therefore lead to unexpected results. It is recommended that applications only use more than one value for ⎕WX as a temporary measure during a conversion project.
- Vince|Dyalog
- Posts: 432
- Joined: Wed Oct 01, 2008 9:39 am
1 post
• Page 1 of 1
Return to Frequently Asked Questions (FAQ)
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group