user type in class 
Author Message
 user type in class

Ok, this has plagued me for a while.

Module.bas:

Public Type MyRect
        Stuff(4) as Integer
End Type

Mine.cls:

Public Sub DrawIt(r as MyRect)
End Sub

WHY do I get a compile error in DrawIt that says "Only public user
defined types can be used as parameters...for public procedures of
class modules". How do I pass a user type to a class?

Robert Chafer
Silverfrost Limited.   http://www.*-*-*.com/
Home to Solar Kingdom, the 3D Solar System Simulator



Sun, 23 Nov 2003 06:48:58 GMT  
 user type in class
try declaring your type at the top of the class file instead of in a module
file


Quote:
> Ok, this has plagued me for a while.

> Module.bas:

> Public Type MyRect
> Stuff(4) as Integer
> End Type

> Mine.cls:

> Public Sub DrawIt(r as MyRect)
> End Sub

> WHY do I get a compile error in DrawIt that says "Only public user
> defined types can be used as parameters...for public procedures of
> class modules". How do I pass a user type to a class?

> Robert Chafer
> Silverfrost Limited.   http://www.silverfrost.com
> Home to Solar Kingdom, the 3D Solar System Simulator



Sun, 23 Nov 2003 07:43:24 GMT  
 user type in class
Hi Rob,

I can't answer the question "why", but you can pass UDTs to class Subs
if you use Friend instead of Public:

Friend Sub DrawIt(r as MyRect)
End Sub

You can pass UDTs to Public class subs if they are are defined in a
"public object module", e.g. in a MultiUse class in an ActiveX DLL.

Regards,

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

Quote:

> Ok, this has plagued me for a while.

> Module.bas:

> Public Type MyRect
>         Stuff(4) as Integer
> End Type

> Mine.cls:

> Public Sub DrawIt(r as MyRect)
> End Sub

> WHY do I get a compile error in DrawIt that says "Only public user
> defined types can be used as parameters...for public procedures of
> class modules". How do I pass a user type to a class?

> Robert Chafer
> Silverfrost Limited.   http://www.silverfrost.com
> Home to Solar Kingdom, the 3D Solar System Simulator



Sun, 23 Nov 2003 10:14:56 GMT  
 user type in class

Quote:

>  try declaring your type at the top of the class file instead of in a module
>  file

Tried that: "cannot declare a public type in a prvate object module".
I need to be able to pass UDTs in. Its a really odd limitation.

Robert Chafer
Silverfrost Limited.   http://www.silverfrost.com
Home to Solar Kingdom, the 3D Solar System Simulator



Sun, 23 Nov 2003 16:23:15 GMT  
 user type in class

Quote:

>  Hi Rob,

>  I can't answer the question "why", but you can pass UDTs to class Subs
>  if you use Friend instead of Public:

>  Friend Sub DrawIt(r as MyRect)
>  End Sub

>  You can pass UDTs to Public class subs if they are are defined in a
>  "public object module", e.g. in a MultiUse class in an ActiveX DLL.

Thanks. I suppose I will have to make it Friend, seems a very odd
limitation though.

Robert Chafer
Silverfrost Limited.   http://www.silverfrost.com
Home to Solar Kingdom, the 3D Solar System Simulator



Sun, 23 Nov 2003 16:24:02 GMT  
 user type in class
Be careful using Friend though, it is an odd thing, and makes it difficult
to create COM+, and MTS Components out of your projects.

If your project is an .exe rather than an Activex.exe, UserControl, or
Activex.dll then all classes are private.  If you created an Activex.DLL
that encapsulated your drawing functions, and set the class Instancing to
one of the public instancing constants then it would work by declaring the
Type in the Class.


Quote:

>  Hi Rob,

>  I can't answer the question "why", but you can pass UDTs to class Subs
>  if you use Friend instead of Public:

>  Friend Sub DrawIt(r as MyRect)
>  End Sub

>  You can pass UDTs to Public class subs if they are are defined in a
>  "public object module", e.g. in a MultiUse class in an ActiveX DLL.

Thanks. I suppose I will have to make it Friend, seems a very odd
limitation though.

Robert Chafer
Silverfrost Limited.   http://www.silverfrost.com
Home to Solar Kingdom, the 3D Solar System Simulator



Sun, 23 Nov 2003 22:25:47 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. User Type as Class Param

2. Passing Classes to other classes (using user defined types)

3. Classes, Collections, and User Defined Types

4. Class and User Defined Types

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

6. Using public user defined types in a class

7. Class Module / User Defined Type

8. User Defined types into a class module

9. Compiler Error Question, attempting to make a class module see a user defined type

10. Classes as user defined Types

11. Passing an array of user-defined data type to a class module

12. User-defined type use in a Class

 

 
Powered by phpBB® Forum Software