Solved

exe files and ocx

Posted on 2001-06-18
6
208 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
Independent Software Vendors: 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!

 
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

Technology Partners: 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

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code 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…

756 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