Using a UDT in a Class method, how to make a class module public 
Author Message
 Using a UDT in a Class method, how to make a class module public

John, thanks, some replies inline..

Quote:

> An class module is an object module (as opposed to a standard .bas module
which
> is not).  Whether it is Public or Private depends on its Instancing
property.
> In a standard EXE you are not aware that a class has an Instancing
property
> because it is always Private, which means that you cannot create an
instance of
> the class from another project/component.  Since it cannot be changed it
does
> not show up as a property in the properties window.

> If, however, you create an ActiveX DLL project you will see that the
default
> Class1 does have an Instancing property, and that that default is
MultiUse.  One
> of the Instancing values you may select is Private.  The others, including
> MultiUse, are all "public".

> So...  If you:
> - define your UDT in the default Class1 of an ActiveX DLL (which is a
Public
> Object Module),
> - remove the UDT definition from your standard EXE,
> - reference the DLL in your standard EXE,
> then you are in business!!  You do not even need to create an instance of
the
> Class1 in the DLL.

Ok, I get it. But then I'd rather just write my structures/UDT's in IDL and
reference the small resultant typelib.

Quote:

> That said, it is much easier to use Friend.  Why does this work?  I
haven't a
> clue.  I have never seen an explanation to this one.

I'm quite new at VB (coming from a C background). My - confused - image is
sofar something like this:
(And I'm propably wrong somewhere..)

1. VB class methods that use UDT's are not supported by Automation (through
IDispatch).
2. Using Friend (vs. Public) will not inculde these methods in at least the
dispatchinterface (but perhaps in the vtable interface??)
3. Since a 'normal' (non-com/activex) VB class module is at runtime
implemented as a COM component (with a dual itf?), the Friend modifier
allows the methods to work.

I'd be very grateful if someone could shed some light on this for me.

I remember reading in 'Essential COM' that at the present time (VB6 I
assume), VB can *use* structs (e.g. UDTs) from a typelib when using a COM
server, but *cannot* be used to build COM servers that use (VB-defined)
UDT's as method parameters.

Quote:

> What is the difference between Public and Friend in a standard EXE?  Well,
you
> can pass UDTs with Friend but not with Public!!  Why?  See above!!

With above said, I'd love to be proven wrong. If someone could post a (very
small) VB6 COM (ActiveX) DLL that uses UDT's in it's public methods (when
using early binding), or explain why such a thing is impossible, I'd be
grateful.

Regards,
Taras



Sun, 30 Jun 2002 03:00:00 GMT  
 Using a UDT in a Class method, how to make a class module public
Ok, a VB COM DLL using a UDT was a breeze actuelly. Of course it will only
be early bound.

Still, I don't get the "Friend" syntax for doing the same thing within a
Standard EXE.

Regards,
Taras



Mon, 01 Jul 2002 03:00:00 GMT  
 Using a UDT in a Class method, how to make a class module public
inline

--
Enrico Sabbadin

http://sabbadin.tripod.com
MTS FAQ: http://sabbadin.tripod.com/mts_faq.htm


Quote:
> Ok, a VB COM DLL using a UDT was a breeze actuelly. Of course it will only
> be early bound.

why ?
you can pass a variant
and then cast the variant to the UDT
Quote:

> Still, I don't get the "Friend" syntax for doing the same thing within a
> Standard EXE.

> Regards,
> Taras



Mon, 01 Jul 2002 03:00:00 GMT  
 Using a UDT in a Class method, how to make a class module public
If that's possible, how does it work? How will the UDT be represented inside
the VARIANT structure?

Regards,
Taras



Mon, 01 Jul 2002 03:00:00 GMT  
 Using a UDT in a Class method, how to make a class module public
Hi Taras

I, like you, would be pleased to have a few more answers.  I just thought that I
would add that UDTs can only be assigned to variants if they are declared in
Public Object Modules.  As VB guru Bruce McKinney ({*filter*} Visual Basic) has
put it:

"I've thought quite a bit about this strange limitation, but I can't think of a
reason for it. No reason is required. Just remember this simple rule: public
UDTs can't be defined in forms or private classes, but they can be defined in
standard modules or public classes, but only the ones defined in public classes
can be stored in Variants, except that the green ones don't come with
extra soy sauce."

Good luck in your search for the "truth".

John...........

Quote:

> If that's possible, how does it work? How will the UDT be represented inside
> the VARIANT structure?

> Regards,
> Taras



Tue, 02 Jul 2002 03:00:00 GMT  
 Using a UDT in a Class method, how to make a class module public
look at IRecordInfo interface in the MSDN library , this should make things
clearer
hth,
--
Enrico Sabbadin

http://sabbadin.tripod.com
MTS FAQ: http://sabbadin.tripod.com/mts_faq.htm
||||| Select Binary Compatibility at least |||||
---------------------------------------------------


Quote:
> If that's possible, how does it work? How will the UDT be represented
inside
> the VARIANT structure?

> Regards,
> Taras



Mon, 19 Aug 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Public Method in a class calling a private method in same class yields ByRef error

2. How to call one VB class module method from another class in an ActiveX dll

3. Error using user-defined type in parameter of public procedure in a class module

4. Class modules 97 - Refering to array within a custom class module

5. Accessing procedures of a class module from another class module

6. How to invoke a method in a class module using CALLTHIS()

7. Classes - Using Classes as method arguments???

8. UDT and class modules

9. UDT as argument to class method

10. Setup Wizard error: No creatable public class module

11. Public arrays in a class module

12. No creatable public class module detected

 

 
Powered by phpBB® Forum Software