Board index » delphi » COM method with a Collection argument??

COM method with a Collection argument??

This sounds like it should be simple but I can't find the answer
anywhere in DejaNews or Delphi help...

I have an ActiveX Dll create in VB containing the following function:

 Public Function FN_PrintDocuments(colDocuments As Collection) As Long

OK, how do I call this method from a Delphi app?  ie, how do I use the
colDocuments collection parameter?  I've found plenty of help for
using COM collection properties, but nothing about COM collection
parameters.  Do I have to import the VBA.dll type library and create a
_Collection?

I could also change the VB side to:

 Public Function FN_PrintDocuments(colDocuments As Variant) As Long

Do this make it easier for me on the Delphi side?

Thanks,
Steve

 

Re:COM method with a Collection argument??


Quote
>parameters.  Do I have to import the VBA.dll type library and create a
>_Collection?

Not being a guru-level dude, I can't say with authority that it's the only
way, but it works for me in many instances doing the same things.

Re:COM method with a Collection argument??


"Stephen M. Smith" <smi...@imagesoftcorp.com> wrote in message
news:p8fi0tglkq2l22tvn7va90qu8jqpcagnh5@4ax.com...

Quote
> This sounds like it should be simple but I can't find the answer
> anywhere in DejaNews or Delphi help...

> I have an ActiveX Dll create in VB containing the following function:

>  Public Function FN_PrintDocuments(colDocuments As Collection) As Long

> OK, how do I call this method from a Delphi app?  ie, how do I use the
> colDocuments collection parameter?  I've found plenty of help for
> using COM collection properties, but nothing about COM collection
> parameters.  Do I have to import the VBA.dll type library and create a
> _Collection?

Yes

Quote
> I could also change the VB side to:

>  Public Function FN_PrintDocuments(colDocuments As Variant) As Long

> Do this make it easier for me on the Delphi side?

Yes, friendlier than VBA.Collection. However, variants/arrays have different
usage syntax than VBA.Collections.

have fun
--
Binh Ly
http://www.techvanguards.com

Re:COM method with a Collection argument??


Hey Binh.  I looked through your web site before posting here...  very
helpful!

But... if I define the parameter as a Variant in the VB activeX dll
function, and that function uses this variable like a VB Collection
(don't need for...each, just Count and Items properties really)...
How do I define the variable within my Delphi app that I will pass as
the parameter?  IStrings?  SafeArray?  OleVariant?  

Can you post a few sample lines of Delphi code that would create this
"collection" variable, adds 3 strings to it, and then passes it as a
param to a activeX dll function?

Thanks,
Steve

Quote
On Wed, 8 Nov 2000 23:03:05 -0800, "Binh Ly" <b...@castle.net> wrote:
>"Stephen M. Smith" <smi...@imagesoftcorp.com> wrote in message
>news:p8fi0tglkq2l22tvn7va90qu8jqpcagnh5@4ax.com...
>> This sounds like it should be simple but I can't find the answer
>> anywhere in DejaNews or Delphi help...

>> I have an ActiveX Dll create in VB containing the following function:

>>  Public Function FN_PrintDocuments(colDocuments As Collection) As Long

>> OK, how do I call this method from a Delphi app?  ie, how do I use the
>> colDocuments collection parameter?  I've found plenty of help for
>> using COM collection properties, but nothing about COM collection
>> parameters.  Do I have to import the VBA.dll type library and create a
>> _Collection?

>Yes

>> I could also change the VB side to:

>>  Public Function FN_PrintDocuments(colDocuments As Variant) As Long

>> Do this make it easier for me on the Delphi side?

>Yes, friendlier than VBA.Collection. However, variants/arrays have different
>usage syntax than VBA.Collections.

>have fun

Re:COM method with a Collection argument??


"Stephen M. Smith" <smi...@imagesoftcorp.com> wrote in message
news:k2vk0t0aarfpd85apjtevckorc26ib1rur@4ax.com...

Quote
> Hey Binh.  I looked through your web site before posting here...  very
> helpful!

> But... if I define the parameter as a Variant in the VB activeX dll
> function, and that function uses this variable like a VB Collection
> (don't need for...each, just Count and Items properties really)...
> How do I define the variable within my Delphi app that I will pass as
> the parameter?  IStrings?  SafeArray?  OleVariant?

For what you want, you'll first need to create a COM collection class that
supports Count and Items. You do this as part of your VB server. When you've
done this, you can create the new collection from Delphi:

var
  Items: _VBCollection;
begin
  Items := CoVBCollection.Create;
  Items.Add (...);
  VBServer.Foo (Items);
end;

have fun
--
Binh Ly
http://www.techvanguards.com

Re:COM method with a Collection argument??


Hey Binh.  I imported the msvbm60.dll type library but gave up trying
to use it (creating _Collection always resulted in "class not
registered"), but you're saying I should just add a collection class
to my VB COM object and use it instead?  That makes a lot more sense.
But is there any way for me to use late binding in Delphi in this
situation?

Regardless, after overloading my brain with way too much info (from
your web site <g> and scanning through countless delphi sources), I
concluded that I should try a variant array instead of the collection
and just change the VB code.  Am I wasting my time trying this path?

Thanks,
Steve.

Quote
On Thu, 9 Nov 2000 19:30:59 -0800, "Binh Ly" <b...@castle.net> wrote:
>"Stephen M. Smith" <smi...@imagesoftcorp.com> wrote in message
>news:k2vk0t0aarfpd85apjtevckorc26ib1rur@4ax.com...
>> Hey Binh.  I looked through your web site before posting here...  very
>> helpful!

>> But... if I define the parameter as a Variant in the VB activeX dll
>> function, and that function uses this variable like a VB Collection
>> (don't need for...each, just Count and Items properties really)...
>> How do I define the variable within my Delphi app that I will pass as
>> the parameter?  IStrings?  SafeArray?  OleVariant?

>For what you want, you'll first need to create a COM collection class that
>supports Count and Items. You do this as part of your VB server. When you've
>done this, you can create the new collection from Delphi:

>var
>  Items: _VBCollection;
>begin
>  Items := CoVBCollection.Create;
>  Items.Add (...);
>  VBServer.Foo (Items);
>end;

>have fun

Other Threads