type in a class problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Olle Lundin

    type in a class problem

    Hi I´m trying to encapsulate a type in a class but I´m getting this
    error message (Compiler error), could you please explain what I´m doing
    wrong.

    /Olle


    Compile error:
    Only public user defined types defined in public object modules can be
    used as parameters or return types för public procedures of class
    modules or as fiedls of public user defined types

    ---

    in module1.bas
    public type MyTestType
    name as String
    end type

    ---

    in MyTestTypeWrapp er.cls

    Private mvarm_block As Module1.MyTestT ype 'local copy

    Public Property Set m_block(ByVal vData As Module1.MyTestT ype)
    Set mvarm_block = vData
    End Property

    Public Property Get m_block() As Module1.MyTestT ype
    Set m_block = mvarm_block
    End Property

    ---

  • Steve Gerrard

    #2
    Re: type in a class problem

    The confusion arises because public, as used in the error message, is not just
    whether the type was declared public, but whether the module it is in is also
    public. A .bas module is not public. In this sense, public means, "would it be
    visible if you built an ActiveX.dll and then used it in another program?"
    Classes yes; modules no. In a regular app, there are no such public modules.

    So what to do? If you are programming with a single app, you could make your
    class members Friend instead of Public. Since a type is not an object, you will
    also need to change the Set property to a Let property. You will also need to
    change the ByVal to ByRef.

    A better plan: make the type private inside the class module, declare a private
    instance, and expose it one element at a time. In your case, a Name property
    that lets and gets the value of mvarm_block.nam e, for instance.

    "Olle Lundin" <olov.lundinSPA MNO@telia.com> wrote in message
    news:ghGbb.2561 7$mU6.59178@new sb.telia.net...[color=blue]
    > Hi I´m trying to encapsulate a type in a class but I´m getting this
    > error message (Compiler error), could you please explain what I´m doing
    > wrong.
    >
    > /Olle
    >
    >
    > Compile error:
    > Only public user defined types defined in public object modules can be
    > used as parameters or return types för public procedures of class
    > modules or as fiedls of public user defined types
    >
    > ---
    >
    > in module1.bas
    > public type MyTestType
    > name as String
    > end type
    >
    > ---
    >
    > in MyTestTypeWrapp er.cls
    >
    > Private mvarm_block As Module1.MyTestT ype 'local copy
    >
    > Public Property Set m_block(ByVal vData As Module1.MyTestT ype)
    > Set mvarm_block = vData
    > End Property
    >
    > Public Property Get m_block() As Module1.MyTestT ype
    > Set m_block = mvarm_block
    > End Property
    >
    > ---
    >[/color]


    Comment

    Working...