Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

exe files and ocx

Posted on 2001-06-18
6
Medium Priority
?
215 Views
Last Modified: 2010-05-02
Hi,

I did the following:

Created an OCX with one button and one method inside:

Private Sub Command1_Click()
   MsgBox UserContorl.Parent.MyFunc
End Sub

Then, I put this OCX in another project(exe project) that
have this method:

Public function MyFunc() as long
   MyFunc = 11223344
End function

It worked, but I can't understand how it worked.
Does the exe project is a COM object ?
Does it has some kind of table that keeps is methods ?

Can anyone explain me this mechanism ?

Thanks


0
Comment
Question by:amavr
6 Comments
 
LVL 2

Expert Comment

by:agriggs
ID: 6203355
<ping>
0
 
LVL 1

Expert Comment

by:Freekeko
ID: 6203366
HUH!!!????!!??!??!??!?!?!?!?!?!??!????!???!??
0
 
LVL 5

Expert Comment

by:gbaren
ID: 6203405
amavr,

Yes, everything in VB 4, 5 and 6 is COM-based. The form containing your OCX is a COM object.

Gary
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Expert Comment

by:bob_online
ID: 6203411
The parent property of the user control is a reference to the form on which it resides.

Since MYFunc is public, and the user control has a reference to the form, it can execute it
s code.

0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 total points
ID: 6203412
Yes, this works for the following reasion:

VB forms are (some special kind of) com objects, and the property USERCONTROL.PARENT will be assigned internally to the usercontrol when the control is loaded. It will refer to the form it is loaded on.
Now the PARENT variable is internally defined AS OBJECT, and thus any method or property called on this variable will be late bound, thus the entry point will only be looked up when the project (ie this line of code) runs.

At that point, VB code will look if the method MyFunc exists on the object PARENT (yes, it is there) and then executes it.

You can simulate similar behaviour with the CallByName method of VB:
Move the form to the top edge of the screen...
Private Sub Form_Load()
  CallByName Me, "Top", vbPropertyLet, 0
End Sub

 
Cheers
0
 
LVL 5

Expert Comment

by:gbaren
ID: 6203440
amavr,

You should handle all the questions you have open. You have a couple from December.

Go to your profile and grade all the questions that are no longer active. You should do this immediately when you get an answer.

Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

783 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