Results 1 to 7 of 7

Thread: Friend Keyword and Practical Use

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    45
    I created a property procedure in a class module.
    The Get procedure is public.
    The Let procedure is friend.
    I compiled the project into a DLL and then added a reference to the new DLL to a brand new project.
    I can still access the friend procedure from code in my new project.


    Because of this I am a little confused as to how or what the friend declare does.

    I thought, for instance, if I created a series of classes and compiled it into a DLL that the friend keyword would allow the different classes in the DLL to communicate the properties to one another without exposing those properties to a project that the compiled DLL was added to. Sorta like handing private messages back in forth in class without the teacher (the new project the DLL was added to) being able to see the notes. =)

    -Gregg
    -NoOBie At LaRg3

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Well, i have use of Friend keyword when i pass or return global types from a class, otherways i get an error, but i'm not sure if this is just something in vb5.

    I think Friend keyword lets properties, functions and subs to be used as if they were public
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Gregg your definition of the Friend keyword is correct.
    If you have declared the Get proceduce as public but the Let procedure as Friend an other project would be able to read the property value but not set a new value to it.

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    45

    What I cannot figure out....

    Okay, so if I compiled the class (with a property that is declared friend) as a DLL then any project I add that to can use that friended property BECAUSE the dll is part of the project and friended properties can be read anywhere in the project they are a part of.

    If I compiled the project as an EXE then another project trying to uses the friended property in that EXE would NOT be able to see it.

    Is that correct?

    Thanks in advance for your help.
    -Gregg
    -NoOBie At LaRg3

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    45

    CreateObject vs. GetObject

    Correct me if I am wrong:

    The only major I see between these two:

    The CreateObject function allows one to create the object TO a certian location. (create the object, put it there)

    The GetObject function allows one to create an object FROM a certian location. (go there, find the object, create it)

    Don't need details, just wondering if that is a good summary.

    thanks in advance
    -Gregg
    -NoOBie At LaRg3

  6. #6
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    If you declare Public property Get and a Friend property Let in your class then it means when you compile your DLL it will be read only property, because property Let won't be exposed to the user. But you can use this property in your code accross your whole application.

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: CreateObject vs. GetObject

    Originally posted by Gregg
    Correct me if I am wrong:

    The only major I see between these two:

    The CreateObject function allows one to create the object TO a certian location. (create the object, put it there)

    The GetObject function allows one to create an object FROM a certian location. (go there, find the object, create it)

    Don't need details, just wondering if that is a good summary.

    thanks in advance
    Yupp, I would say that that is a correct description.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width