C++ カスタム コマンドが配列を戻すとき、呼び出し側が受け取る値は、スクリプト言語によって、また、CValueArray と CRefArray のどちらが戻されるかによって決まります。たとえば、コマンドが CValueArray を戻す場合、JScript の呼び出し側は安全な配列を取得しますが、コマンドが CRefArray を戻す場合、JScript の呼び出し側は XSICollection を取得します。
| 戻り値 |
||
|---|---|---|
| 言語 |
CRefArray |
CValueArray |
| VBScript |
XSICollection |
XSICollection |
| JScript |
XSICollection |
safe array |
| PerlScript |
XSICollection |
array |
| Python |
XSICollection のインスタンス |
tuple |
JScript の例: 配列を戻す C++ コマンドの呼び出し
//
// GetValueArray() is a C++ custom command that returns a CValueArray
//
var aSafeArray = GetValueArray();
var aVBArray = new VBArray( aSafeArray );
logmessage( typeof( aVBArray ) );
logmessage( aVBArray.dimensions() );
// Access the VBArray directly
for (var i=0; i <= aVBArray.ubound(1); i++)
{
Application.LogMessage( aVBArray.getItem(i).fullname );
}
// Convert the VBArray to a JScript array
var aJSarray = aVBArray.toArray();
for (e=new Enumerator(aJSarray);!e.atEnd();e.moveNext())
{
var o = e.item();
logmessage( o.fullname );
}
//
// GetRefArray() is a C++ custom command that returns a CRefArray
//
var objects = GetRefArray();
logmessage( objects.type ); //INFO : XSICollection
for (e=new Enumerator(objects);!e.atEnd();e.moveNext())
{
var o = e.item();
Application.LogMessage( o.fullname );
}Python の例: 配列を戻す C++ コマンドの呼び出し
# # GetValueArray is a C++ custom command that returns a CValueArray # objects = Application.GetValueArray() Application.Logmessage( unicode(type(objects)) )#INFO : <type 'tuple'> for o in objects: Application.LogMessage( o.name ) Application.Logmessage( unicode(type(o)) )#INFO : <type 'instance'> Application.LogMessage( Application.classname(o) ) # # GetRefArray is a C++ custom command that returns a CRefArray # objects = Application.GetRefArray() Application.Logmessage( unicode(type(objects)) )#INFO : <type 'instance'> Application.Logmessage( objects.type )# XSICollection for o in objects: Application.LogMessage(o.name) for i in range(objects.Count): Application.LogMessage(objects(i).FullName)
VBScript の例: 配列を戻す C++ コマンドの呼び出し
' ' GetValueArray() returns a CValueArray ' set objects = GetValueArray() logmessage( typename( objects ) )'INFO : Object logmessage( objects.type )'INFO : XSICollection for each o in objects logmessage o.name next ' ' GetRefArray() returns a CRefArray ' set objects = GetRefArray() logmessage typename( objects )'INFO : Object logmessage( objects.type )'INFO : XSICollection for each o in objects logmessage o.name next
PerlScript の例: 配列を戻す C++ コマンドの呼び出し
#
# GetRefArray() returns a CRefArray
#
# scalar context
my $objects = GetRefArray();
$Application->LogMessage( $objects->Type );#INFO : XSICollection
for $i (0..$objects->Count-1) {
$o = $objects->Item($i);
$Application->LogMessage( $o->IsKindOf("polymsh") );
$Application->LogMessage( $o->{'FullName'} );
}
# list context
my @objects = GetRefArray();
$Application->logmessage( $objects[0]->Type ); #INFO : XSICollection
for $i (0..$objects[0]->Count-1) {
$o = $objects[0]->Item($i);
$Application->LogMessage( $o->IsKindOf("polymsh") );
$Application->LogMessage( $o->{'FullName'} );
}
#
# Test() returns a CValueArray
#
# list context
my @test = Test();
$Application->LogMessage( ref( $test[0] ) ); #INFO : ARRAY
for $o (@{$test[0]}) {
$Application->LogMessage( $o->FullName );
}
# scalar context
my $test = Test();
$Application->LogMessage( ref( $test ) ); #INFO : ARRAY
for $o (@{$test}) {
$Application->LogMessage( ref( $o ) ); #INFO : Win32::OLE
$Application->LogMessage( $o->FullName );
}