CreateObject and late binding 
Author Message
 CreateObject and late binding

Hello vb gurus,

This one is about a form object named form1 that i want to use in
late-binding.

So let's say that i have a nice .bas file that has 2 functions. The first
one is doing something with the form1 object that i have in my project like
form1.DoSomething. The second function is doing some calculations.

Someone else wants to use my second function, so if we include the .bas
file in his project, the first function has a reference to the form1 object
witch dont exist in his project, so it does not compile.

So my question : Is there a way to refererence a form object by any other
means then the actual name of the object form1. I've tryed to make a
CreateObject("MyProject.Form1") or something like that, so anyone else
using my .bas file dont needs to have a form1 object.

I hope this does not sound to complicated, thanks for any help.
Sorry for the duplicated post...

Bruno



Tue, 06 Mar 2001 03:00:00 GMT  
 CreateObject and late binding
Bruno...

In general, using the form name as a reference to a form object
is a weird special case (and something we never do here).

Instead, we instantiate forms (and other objects) in object
variables:

   Dim frmForm1_ptrA as Form1   ' strongly-typed
   Dim frmForm1_ptrB as Form     ' less strongly-typed

Somewhere in your code, e.g. in a Sub Main, you instantiate these via:

   Set frmForm1_ptrA = New Form1   ' creates and initializes the form
   Set frmForm1_ptrB = frmForm1_ptrA   ' another pointer to it

Somewhere after creating the form, you can pass it to your module:

   Call bas_module_procX(inForm:=frmForm1_ptrA)

You create your .bas module with a procedure like:

   Public Sub bas_module_procX(inForm As Form)
      ' Input: inForm is any VB form, accessed via late-binding
      Call inForm.<method>   ' ref to any property via late-binding
   End Sub

Using the form name like a variable is in fact using an implicit
public variable associated with each form definition. There's only
one per form, so you can see how this would break down with
multiple instances of a given form. It also leads to lots of confusion,
and must be explicitly cleared in order to release the form instance.

I hope I've addressed your question.

--

Quote:

>So my question : Is there a way to refererence a form object by any other
>means then the actual name of the object form1. I've tryed to make a
>CreateObject("MyProject.Form1") or something like that, so anyone else
>using my .bas file dont needs to have a form1 object.



Tue, 06 Mar 2001 03:00:00 GMT  
 CreateObject and late binding
The solution given by Hanson is what u "shud" b doing. But if u wanna do
what u just said - that can also be done (remember it is not the best
way though). Instead of making your App as a Standard EXe - make it a
AxtiveX EXE - which makes it an OLE Server - out-of-process ofcourse.
now u can reference this App in any other project.

So say if u call the project Project1 then u can access the exposed
objects as Project1.ObjectName

The Catch is when u make a Setup - then it gives u 2 options - Install
as a Shared Component or Install as a standalone component. If u select
teh firstthen the app is registered on the client Machine as a sahred
components - so the exe is NOT installed in
c:\whatever-folder-u-selected but is in c:\windows (or wherever your
windows directory is)!

I say again the solution provided by Hanson os the one u shud b using.

--
Cheerio,
       _____
      (, /  |        ,
        /---| ___     _/_            
     ) /    |_// (__(_(__          

It is impossible to make anything foolproof because fools are so
ingenious.

Quote:

> Hello vb gurus,

> This one is about a form object named form1 that i want to use in
> late-binding.

> So let's say that i have a nice .bas file that has 2 functions. The first
> one is doing something with the form1 object that i have in my project like
> form1.DoSomething. The second function is doing some calculations.

> Someone else wants to use my second function, so if we include the .bas
> file in his project, the first function has a reference to the form1 object
> witch dont exist in his project, so it does not compile.

> So my question : Is there a way to refererence a form object by any other
> means then the actual name of the object form1. I've tryed to make a
> CreateObject("MyProject.Form1") or something like that, so anyone else
> using my .bas file dont needs to have a form1 object.

> I hope this does not sound to complicated, thanks for any help.
> Sorry for the duplicated post...

> Bruno



Tue, 06 Mar 2001 03:00:00 GMT  
 CreateObject and late binding
The solution given by Hanson is what u "shud" b doing. But if u wanna do
what u just said - that can also be done (remember it is not the best
way though). Instead of making your App as a Standard EXe - make it a
AxtiveX EXE - which makes it an OLE Server - out-of-process ofcourse.
now u can reference this App in any other project.

So say if u call the project Project1 then u can access the exposed
objects as Project1.ObjectName

The Catch is when u make a Setup - then it gives u 2 options - Install
as a Shared Component or Install as a standalone component. If u select
teh firstthen the app is registered on the client Machine as a sahred
components - so the exe is NOT installed in
c:\whatever-folder-u-selected but is in c:\windows (or wherever your
windows directory is)!

I say again the solution provided by Hanson os the one u shud b using.

--
Cheerio,
       _____
      (, /  |        ,
        /---| ___     _/_            
     ) /    |_// (__(_(__          

It is impossible to make anything foolproof because fools are so
ingenious.

Quote:

> Hello vb gurus,

> This one is about a form object named form1 that i want to use in
> late-binding.

> So let's say that i have a nice .bas file that has 2 functions. The first
> one is doing something with the form1 object that i have in my project like
> form1.DoSomething. The second function is doing some calculations.

> Someone else wants to use my second function, so if we include the .bas
> file in his project, the first function has a reference to the form1 object
> witch dont exist in his project, so it does not compile.

> So my question : Is there a way to refererence a form object by any other
> means then the actual name of the object form1. I've tryed to make a
> CreateObject("MyProject.Form1") or something like that, so anyone else
> using my .bas file dont needs to have a form1 object.

> I hope this does not sound to complicated, thanks for any help.
> Sorry for the duplicated post...

> Bruno



Tue, 06 Mar 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. early binding vs late binding

2. Activex Server - Early Binding vs. Late Binding

3. Late Binding vs Early Binding in out-of-process servers

4. * Early binding or late binding

5. Early binding and Late binding

6. early binding / late binding

7. Early binding and Late binding in VB.

8. Early Binding and Late Binding

9. Early bind and Late bind in VB.

10. Early binding and Late binding in VB.

11. early binding vs late binding

12. Early Binding - Late Binding

 

 
Powered by phpBB® Forum Software