Solved

Why need Adding reference and adding component

Posted on 2004-07-30
14
160 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
14 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 32 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 31 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 31 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
 
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 31 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now