Multi-Form Issue 
Author Message
 Multi-Form Issue

I have an App the creates multiple instances of two forms.  These two forms
are paired (ie., A1, A2...  B1, B2...  C1, C2...)

These forms are created by:
set f1= new Form1
set f2= new Form2

So I have multiple instances of f1 and f2...

How do I make sure that if I perform an action on A1 that the data will be
written to A2 and not B2 or C2???

Each pair of forms had an identical keyname property that I set when they
are created...

Is there a way to say that if A1 is performing an action...  A2 should
receive the result of the action?



Wed, 29 Jun 2011 02:11:01 GMT  
 Multi-Form Issue

Quote:

> I have an App the creates multiple instances of two forms.  These two forms
> are paired (ie., A1, A2...  B1, B2...  C1, C2...)

> These forms are created by:
> set f1= new Form1
> set f2= new Form2

> So I have multiple instances of f1 and f2...

> How do I make sure that if I perform an action on A1 that the data will be
> written to A2 and not B2 or C2???

> Each pair of forms had an identical keyname property that I set when they
> are created...

> Is there a way to say that if A1 is performing an action...  A2 should
> receive the result of the action?

That's a kind of bizzare design, but yeah, they'll need to keep a reference to one
another of some sort.  Perhaps each other's hWnd?  You could design a custom
property (say, hWndBuddy) for each of the forms, and hook 'em up like this:

  set f1= new Form1
  set f2= new Form2
  f1.hWndBuddy = f2.hWnd
  f2.hWndBuddy = f1.hWnd

Then, to get a (COM) reference to the appropriate buddy, it's as simple as iterating
the Forms collection looking for the matching hWnd.
--
.NET: It's About Trust!
 http://vfred.mvps.org



Wed, 29 Jun 2011 03:34:50 GMT  
 Multi-Form Issue


Quote:

>> I have an App the creates multiple instances of two forms.  These two
>> forms
>> are paired (ie., A1, A2...  B1, B2...  C1, C2...)

>> These forms are created by:
>> set f1= new Form1
>> set f2= new Form2

>> So I have multiple instances of f1 and f2...

>> How do I make sure that if I perform an action on A1 that the data will
>> be
>> written to A2 and not B2 or C2???

>> Each pair of forms had an identical keyname property that I set when they
>> are created...

>> Is there a way to say that if A1 is performing an action...  A2 should
>> receive the result of the action?

> That's a kind of bizzare design, but yeah, they'll need to keep a
> reference to one another of some sort.  Perhaps each other's hWnd?  You
> could design a custom property (say, hWndBuddy) for each of the forms, and
> hook 'em up like this:

>  set f1= new Form1
>  set f2= new Form2
>  f1.hWndBuddy = f2.hWnd
>  f2.hWndBuddy = f1.hWnd

> Then, to get a (COM) reference to the appropriate buddy, it's as simple as
> iterating the Forms collection looking for the matching hWnd.

Just like Karl suggested, but you can use the Tag property, or you can use a
variable that refer to the associated form. Example:

Add to the general section of Form1:

Public frmForm2 As Form2

Add a similar variable to Form2, then use:

set f1= new Form1
set f2= new Form2

Set f1.frmForm2 = f2
Set f2.frmForm1 = f1

This adds additional reference to the same object. Make sure that you set
frmFormX = Nothing, otherwise it will not be unloaded. Objects are unloaded
when the reference count reaches 0.



Wed, 29 Jun 2011 04:02:21 GMT  
 Multi-Form Issue

Quote:

>>> Is there a way to say that if A1 is performing an action...  A2 should
>>> receive the result of the action?

>> That's a kind of bizzare design, but yeah, they'll need to keep a
>> reference to one another of some sort.  Perhaps each other's hWnd?  You
>> could design a custom property (say, hWndBuddy) for each of the forms, and
>> hook 'em up like this:

>>  set f1= new Form1
>>  set f2= new Form2
>>  f1.hWndBuddy = f2.hWnd
>>  f2.hWndBuddy = f1.hWnd

>> Then, to get a (COM) reference to the appropriate buddy, it's as simple as
>> iterating the Forms collection looking for the matching hWnd.

> Just like Karl suggested, but you can use the Tag property, or you can use a
> variable that refer to the associated form. Example:

> Add to the general section of Form1:

> Public frmForm2 As Form2

> Add a similar variable to Form2, then use:

> set f1= new Form1
> set f2= new Form2

> Set f1.frmForm2 = f2
> Set f2.frmForm1 = f1

> This adds additional reference to the same object. Make sure that you set
> frmFormX = Nothing, otherwise it will not be unloaded. Objects are unloaded
> when the reference count reaches 0.

Yeah, I didn't want to get into the circular reference mess, since it was so easy to
avoid in this case.  But using the Tag would be one easy way to avoid adding a
custom property, unless it's already in use for something else.
--
.NET: It's About Trust!
 http://vfred.mvps.org


Wed, 29 Jun 2011 04:55:55 GMT  
 Multi-Form Issue
Thanks for the responses...  ended up doing pretty much what you both
suggested.  Since I already had the Window "Key" property set on each form...
 I used that as my identifier.  

I'm in the process of reworking old code now to tie it all together.  Glad
that the responses matched my method.

Quote:


> >>> Is there a way to say that if A1 is performing an action...  A2 should
> >>> receive the result of the action?

> >> That's a kind of bizzare design, but yeah, they'll need to keep a
> >> reference to one another of some sort.  Perhaps each other's hWnd?  You
> >> could design a custom property (say, hWndBuddy) for each of the forms, and
> >> hook 'em up like this:

> >>  set f1= new Form1
> >>  set f2= new Form2
> >>  f1.hWndBuddy = f2.hWnd
> >>  f2.hWndBuddy = f1.hWnd

> >> Then, to get a (COM) reference to the appropriate buddy, it's as simple as
> >> iterating the Forms collection looking for the matching hWnd.

> > Just like Karl suggested, but you can use the Tag property, or you can use a
> > variable that refer to the associated form. Example:

> > Add to the general section of Form1:

> > Public frmForm2 As Form2

> > Add a similar variable to Form2, then use:

> > set f1= new Form1
> > set f2= new Form2

> > Set f1.frmForm2 = f2
> > Set f2.frmForm1 = f1

> > This adds additional reference to the same object. Make sure that you set
> > frmFormX = Nothing, otherwise it will not be unloaded. Objects are unloaded
> > when the reference count reaches 0.

> Yeah, I didn't want to get into the circular reference mess, since it was so easy to
> avoid in this case.  But using the Tag would be one easy way to avoid adding a
> custom property, unless it's already in use for something else.
> --
> ..NET: It's About Trust!
>  http://vfred.mvps.org



Wed, 29 Jun 2011 05:11:01 GMT  
 Multi-Form Issue


Quote:
> Thanks for the responses...  ended up doing pretty much what you both
> suggested.  Since I already had the Window "Key" property set on each
form...
>  I used that as my identifier.

> I'm in the process of reworking old code now to tie it all together.  Glad
> that the responses matched my method.

In addition to everyone's sage advice. Consider that whenever you have to
two thingies so intimately associated, it is useful to go the next step and
make the association a type in itself. Create a 'factory' class to manage
their lifetimes (creation, configuration, and destruction) as well as
provide Event management between them and the outside world.

-ralph



Wed, 29 Jun 2011 23:03:10 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Multi-form/Multi-database synchro

2. Integrity issues with multi-user MS Access database

3. Multi user issues

4. Browser-based vs. Multi-tier development issues

5. multi user issues in access

6. Database Connectivity: Multi-User Issues

7. Multi User Security Issue

8. VB ADO multi-user issues

9. multi-threaded issue?

10. VB ADO multi-user issues

11. Integrity issues with multi-user MS Access database

12. Database Connectivity: Multi-User Issues

 

 
Powered by phpBB® Forum Software