Complex Form array question

sethindeed
10-04-2001, 08:50 AM
Hello,
OK, here is my problem.
I am coding a program which contains an MDIForm and two types of MDIChild forms : Queries and Templates. I load both of those forms with arrays ( i.e frmTemplate ( i ) ). I have indexes that keeps track of the total, current and childcount indexes. The project is working quite well, the only concern left is the following one :
When I am unloading a Template form, in the QueryUnload Event, I am coding :
TotalTemplate = TotalTemplate - 1
And when I am loading a new Template occurence, I am coding :
frmTemplate ( TotalTemplate ).Show
TotalTemplate = TotalTemplate + 1
I am getting to the problem, just want to give you as much informations as possible...
When doubleclicking on a grid, I am calling the following routine to find out if a particular template is already in memory :

Private Sub MSFlexGrid1_DblClick()
If MSFlexGrid1.MouseRow <> 0 Then
If MSFlexGrid1.Rows > 1 Then
If MSFlexGrid1.TextMatrix(1, 1) <> "" Then
MSFlexGrid1.Enabled = False
For aCounter = 1 To TotalTemplate - 1
TempBug = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)
frmTemplate(aCounter).IfOpen (TempBug)
If ResultB = True Then
Exit For
End If
Next aCounter
If ResultB = True Then
frmTemplate(aCounter).WindowState = 0
frmTemplate(aCounter).SetFocus
Else
ReDim Preserve frmTemplate(1 To TotalTemplate)
TempBugIdent = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)
TemplateType = "DoubleClick"
frmTemplate(TotalTemplate).Show
TotalTemplate = TotalTemplate + 1
ChildCount = ChildCount + 1
End If
MSFlexGrid1.Enabled = True
End If
End If
End If
End Sub

The problem with this routine is that in the For Next loop, the program will call this coded line:
frmTemplate(aCounter).IfOpen (TempBug)
...which means it will look in frmTemplate( 1 ), frmTemplate ( 2 ), frmTemplate ( 3 )...
...But if I opened 4 occurences of frmTemplate, then closed the third one, there will be three checks ( which is correct ), but when it will call frmTemplate ( 3 ), it will look to the old frmTemplate unloaded instead of having dynamically reassigned frmTemplate ( 4 ) to frmTemplate ( 3 ).
If you are still following, is there a way to dynamically reassign form indexes when certain forms are unloaded, to keep the workflow functionnal ?
Thank you very much :)

Derek Stone
10-04-2001, 06:51 PM
You might be able to keep track of all the open windows by placing them in an array, or even better yet a collection.
Then, just loop through the array/collection to find all of the open windows.

Good Luck
-cl

sethindeed
10-05-2001, 06:58 AM
...And how can I know if a form is open or not...?

karimahta
10-06-2001, 12:49 AM
You know, looking at what you are trying to achieve, I think it might be worthwhile moving the responsibilty for the tracking of your templates to the MDIform and creating a set of Public Properties and Methods that handle the template collection. Or even better, create a collection type class module that is exposed as a property in the MDIForm.

This collection class (call it colTemplates) would handle the opening of a new template form and keep a collection of open template forms. Then it is just a matter of iterating through the collection using the For ... Each construct rather than depending on indexes.

You could also assign a unique key to each open template form that identifies it through it's natural life.

When each template form unloads, it calls a method (e.g. DeRegister) of the colTemplate object that removes the from from the collection.

This way the handling of the collection takes place in a collection object at the MDIForm level, rather than the children having to look after themselves. You could even let the children (the template forms) have a ColParent property that holds a reference to the colTemplate object.

Anyway, enough from me.

HTH

<font color=blue>I once had an itch that I scratched and off fell my leg.</font color=blue>

anhmytran
10-06-2001, 06:59 AM
To know the form "FormA" open or not:

Dim frm As Form
For Each frm in Forms
If frm.Name = "FormA" Then MsgBox "FormA is already loaded."
Next

When a form is loaded and not yet unload and set to nothing
it is in the application's Forms (the Form collection).

AnhMy_Tran

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum