?
Solved

Why need Adding reference and adding component

Posted on 2004-07-30
14
Medium Priority
?
165 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:leekf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 128 total points
ID: 11677058
>>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
 
LVL 11

Assisted Solution

by:Babycorn-Starfish
Babycorn-Starfish earned 124 total points
ID: 11677068
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
 
LVL 7

Assisted Solution

by:_agj_
_agj_ earned 124 total points
ID: 11677147
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Author Comment

by:leekf
ID: 11677231
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
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 11677592
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
 
LVL 14

Assisted Solution

by:aelatik
aelatik earned 124 total points
ID: 11677678
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 11677909
aelatik said it all

8->
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 11677916
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
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 11678179
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
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 11678321
Although i'm not at all confident of that now.

BS
0
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 11678425
Just checked in Vb 6......

Please disregard all comments - it will compile !


BS
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 11682898
>>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

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question