Why need Adding reference and adding component

1. what is the use of adding "Project" -> "References" ??

How to determine when I need to add references?


2. what is the use of adding "Project" -> "Component" ??

How to determine when I need to add component?

If I added component for the project, does it mean Package and deployment wizard will automatically add the ocx file to the setup package?

Thanks
LVL 2
leekfAsked:
Who is Participating?
 
EDDYKTCommented:
>>1. what is the use of adding "Project" -> "References" ??

If you use early binding, otherwise you don't have to

>>2. what is the use of adding "Project" -> "Component" ??

If you use ocx, then you have to add component before you use

>>If I added component for the project, does it mean Package and deployment wizard will automatically add the ocx file to the setup package?

Yes if you point to your .vbp file
0
 
Babycorn-StarfishCommented:
Hi,

you need to add References in order to access functions from libraries that aren't 'normally' part of VB. For example you can add a reference to the Microsoft Word object library and thus access functionality such as mail merge, etc.

BS
0
 
_agj_Commented:
references are generally dlls, etc which u use to get libraries like the word obj library as suggstd...

components gen. list those controls that u place on the form and use...

the Pack n dep wiz gets both ur ref and cmpnents detls from ur vbp...so will pack em in...

as to determining when to use ref/component...i shud say...if u want to say access excel library....create an xls and do stuff...refer to the library in references and code for it.
if u want to place a control like say winsock control(to do network communic stuff)...use components...
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
leekfAuthor Commented:
BS:
If I don't add references, can the program be run?

Ie to ask: will adding reference affect the final product or will it just have effect during development process.



EDDYKT:
Could you tell what is early binding?

How can I know if I use ocx? eg: Does Adodc use ocx? How about DataGrid?

Thank you very much!! You are great guys!
0
 
Babycorn-StarfishCommented:
Hi,

"If i don't add references, can the program be run?"

In my experience it shouldn't even compile, as the compiler won't recognize the methods, properties etc that you are referring to. You should also notice that the intellisense (or whatever it is pre VS 2003) won't give you anything after the dot when you try to refer to a method etc. To cut a long story short the Visual Studio will pull you up short, you shouldn't even get past pressing enter without it turning red, error dialog box, etc.

Best of luck with whatever you're doing leekf, keep at it :)

BS
0
 
aelatikCommented:
When you add a reference to a specific object VB will help you by showing the drop down box containing the properties and methods for that object.
You actualy don't need to add references and can use late binding.

For Example the reference "Microsoft Internet Controls :
   
-------------------------------------------------------------------------------------------------------------------------------
   
   
With Early binding you declare the object like this :
   
Dim IE As New InternetExplorer
       
Good thing about Early binding
- The package and deployment wizard automatically includes all neccesarry files.
- VB helps you show the properties and methods for an object
     
Bad thing about Early binding
- If the referenced class is not available on the target computer then you app CAN't and Won't start.
- If the referenced class is available but with another version your app won't start either
       

-------------------------------------------------------------------------------------------------------------------------------


With Late binding you declare the object like this

Dim IE
Set IE = CreateObject("internetexplorer.application") ' the classnames can be found in the registry "HKEY_CLASSES_ROOT" section
' Check if the object exist
 If IsObject(IE) Then MsgBox "Object Exist"
       
Good thing about Late binding
- Your application can always start if you handle the errors well
- If the referenced object is available in another version it will simply use that one.
     
Bad thing about Early binding
- You have to lookup which classnames to use
- You have to lookup the methods and properties to use ( no VB help ! )
- Package and Deployment wizard does not know which files to include
0
 
EDDYKTCommented:
aelatik said it all

8->
0
 
EDDYKTCommented:
By the way

>>In my experience it shouldn't even compile, as the compiler won't recognize the methods, properties etc that you are referring to.


it is NOT true
0
 
Babycorn-StarfishCommented:
Ahem,

I'll back peddle a little and say that by using Dim instead of CreatObject it shouldn't compile. I hope !! lol :)

BS
0
 
Babycorn-StarfishCommented:
Although i'm not at all confident of that now.

BS
0
 
Babycorn-StarfishCommented:
Just checked in Vb 6......

Please disregard all comments - it will compile !


BS
0
 
zzzzzoocCommented:
>>In my experience it shouldn't even compile, as the compiler won't recognize the methods, properties etc that
>>you are referring to.

For objects that are late-bound, the compiler doesn't (and can't) check the methods/properties supported by the object's interface since they're unknown (IUnknown interface). So, as said, you can compile the project fine. If the object is early-bound, then the compiler knows what interface the object is *supposed* to have and won't compile if invalid methods/properties are used.

At run-time, for objects using IUnknown, each method/property is queried to see if the object's interface supports it. If not, it'll error. For early-bound objects, no interface querying is required so it's much faster.

..or something along those lines.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.