Solved

exe files and ocx

Posted on 2001-06-18
6
210 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
[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
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
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 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 100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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
Course of the Month9 days, 9 hours left to enroll

623 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