Re: How to get an OLE array of objects?



Hi Paul, thanks for the response!

use Win32::OLE;
my $tree = Win32::OLE->new( 'Tree.Component' );
my @nodes = array();

This is not Perl. Are you thinking of PHP, perhaps? To declare an
array, you simply say:
my @nodes;

Yes, you're probably right. I'm definitely using Perl for this
project, but I'm working on another project in PHP at the same time.
(You should see how many times both intepreters have basically told me,
"You can't do that, stupid!") If you see something that is PHP-ish,
please imagine that it's actually in Perl. That last line should have
just been:

my @nodes;

$tree->GetNodes(\@nodes); # This doesn't work...

What do you mean by "doesn't work"? Did that give you a syntax error?
Run-time error? Or are you just assuming that it "didn't work" based
on later code?

No, it doesn't give any kind of error, but if I issue a print @nodes; I
get zero (no elements) even though I've verified in another utility
that the function, when called correctly, does indeed return results.
(Around 89 nodes, actually.)

for $node (@nodes) {
print $node{Name}."\n"; # Name is a property of TreeNode objects

Are you using strict and warnings? If not, turn them on. Here, you're
trying to access a hash named %node, rather than a hashref named $node.
Assuming @nodes does contain an array of hashes (or objects), this
should be:
print $node->{Name} . "\n";

@nodes is actually (or rather, supposed to be, but isn't, which is the
root of my problem) an array of OLE TreeNode objects. Looking at the
documentation again, I think you're right, the properties of an OLE
object are stored as a hashref, not a hash, and the it should be
$node->{Name}. At this time, though, neither works, because the @nodes
array is completely empty and the loop never gets entered.

I included the other guy's sample code I found related to this (copied
again below, with a few extra lines for clarification) because I
*think* that the answer is that I have to pass some kind of Variant to
the function. That's what he does to get a double value passed out of
the OLE method that takes an [out] parameter (a parameter that gets
changed within the OLE object method). But if I do that, what kind of
Variant do I pass in? And how do I get access to the OLE objects I get
back?

use Win32::OLE;
use Win32::OLE::Variant;
my $arg4 = Variant( VT_R8 | VT_BYREF, 0.0);
my $service = Win32::OLE->new( '3rdPartyComponent.Service' );
$service->foo( 31, 4000, 28000, $arg4 );
# That last parameter is a double, whose value gets altered within
# and passed back out of the foo method of the $service object.

Thanks!

.



Relevant Pages

  • Expanding scalar hash element in array ref.
    ... array reference with the original scalar as a first element of the ... want to convert the following PHP code into Perl: ...
    (comp.lang.perl.misc)
  • Expanding scalar hash element in array ref.
    ... array reference with the original scalar as a first element of the ... want to convert the following PHP code into Perl: ...
    (comp.lang.perl)
  • Re: file delimited
    ... array fgetcsv (resource handle, int length [, string delimiter [, string ... PHP manual extract: ... > I'm new to php I just come from perl, and I wanted to know like perl if we ...
    (php.general)
  • Re: Nested arrays
    ... Against PHP, hashes are widely used in Perl. ... Perl makes a certain difference between hashes and arrays. ... assign a reference of an array to a hash key. ...
    (comp.lang.perl.misc)
  • How to get an OLE array of objects in Perl?
    ... I posted it over in a Perl ... I have an OLE object with a method that takes an parameter (a ... What I'd like to do is to get that array ... of other OLE objects and iterate through them, ...
    (microsoft.public.win32.programmer.ole)