Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

exe files and ocx

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
amavr
Asked:
amavr
1 Solution
 
agriggsCommented:
<ping>
0
 
FreekekoCommented:
HUH!!!????!!??!??!??!?!?!?!?!?!??!????!???!??
0
 
gbarenCommented:
amavr,

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

Gary
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
bob_onlineCommented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
gbarenCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now