Usercontrol's never been terminated
Hi all,
I create an ActiveX control which needs to link with MSFlexGrid. This
is my component model:
MyControl (usercontrol)
|
+------ Datasource (Get Property () as CDatasrc class)
|
+ ---- Tablesource (Get Property () as
CTable class)
|
+ ----- Table (Set
Property (Byval vData as Object)
I attached my control on the another usercontrol (as Web container),
because I would like to create Web application.
The problem is that it wouldn't been terminated when user closed IE. I mean
that Usercontrol_Terminated event of Usercontrol container (not mycontrol)
has never been raised. I had tested something and found that:
If I set like this : Set MyControl1.Datasource.Tablesource.Table =
Grid <-- msflexgrid
<< code within Property Table>>
Dim m_objFlex as MSFlexGrid
Public Set Property Table(Byval vData as Object)
Set m_objFlex = vData
End Property
<< >>
My web-app has never been shut-down. If I didn't set this property, it
can terminate properly. Unfortunately, I have to use MSFlexGrid as a datasource
for my control, and I need to let my control to work on MSFlexGrid; such
as fill data, or change color in MSFlexGrid.
I try to set m_objFlex to nothing before closing the Web, it can terminate
properly. Unfortunately, I can't track when user needs to close the Web.
Indeed, the Web should be terminated properly when user closed the Web.
That's the problem. How can I solve this problem?
Thank you
Rattagarn V.
Re: Usercontrol's never been terminated
Rattagarn,
I remember answering this question before. Didn't my previous suggestion
work?
Michael Culley
"Rattagarn V." <rattagarn@hotmail.com> wrote:
>
>Hi all,
>
> I create an ActiveX control which needs to link with MSFlexGrid. This
>is my component model:
>
> MyControl (usercontrol)
> |
> +------ Datasource (Get Property () as CDatasrc class)
> |
> + ---- Tablesource (Get Property () as
>CTable class)
> |
> + ----- Table (Set
>Property (Byval vData as Object)
>
> I attached my control on the another usercontrol (as Web container),
>because I would like to create Web application.
>
>The problem is that it wouldn't been terminated when user closed IE. I
mean
>that Usercontrol_Terminated event of Usercontrol container (not mycontrol)
>has never been raised. I had tested something and found that:
> If I set like this : Set MyControl1.Datasource.Tablesource.Table
=
>Grid <-- msflexgrid
>
> << code within Property Table>>
> Dim m_objFlex as MSFlexGrid
> Public Set Property Table(Byval vData as Object)
> Set m_objFlex = vData
> End Property
> << >>
>My web-app has never been shut-down. If I didn't set this property, it
>can terminate properly. Unfortunately, I have to use MSFlexGrid as a datasource
>for my control, and I need to let my control to work on MSFlexGrid; such
>as fill data, or change color in MSFlexGrid.
>
> I try to set m_objFlex to nothing before closing the Web, it can terminate
>properly. Unfortunately, I can't track when user needs to close the Web.
> Indeed, the Web should be terminated properly when user closed the Web.
> That's the problem. How can I solve this problem?
>
>Thank you
>Rattagarn V.
Re: Usercontrol's never been terminated
Hi
Thank you for Micheal Culley's reponse and his last good tip.
I tried to use your solution with the problem I got. Unfortunately, it didn't
work. Now I have no problem about Parent/Child circular reference. I tested
this by implementing a small active X project and has the parent/child relationships.
It runs and shutdown properly. Unintentionally, I found the another error
which probably caused the shutdown problem of the control. It is my last
posted message. So I used your solution as I told, but it didn't work.
What should I deal with this problem?
Best Regards
Rattagarn V.
"Michael Culley" <m_culley@one.net.au> wrote:
>
>Rattagarn,
>
>I remember answering this question before. Didn't my previous suggestion
>work?
>
>Michael Culley
>
>
>"Rattagarn V." <rattagarn@hotmail.com> wrote:
>>
>>Hi all,
>>
>> I create an ActiveX control which needs to link with MSFlexGrid.
This
>>is my component model:
>>
>> MyControl (usercontrol)
>> |
>> +------ Datasource (Get Property () as CDatasrc class)
>> |
>> + ---- Tablesource (Get Property () as
>>CTable class)
>> |
>> + ----- Table (Set
>>Property (Byval vData as Object)
>>
>> I attached my control on the another usercontrol (as Web container),
>>because I would like to create Web application.
>>
>>The problem is that it wouldn't been terminated when user closed IE. I
>mean
>>that Usercontrol_Terminated event of Usercontrol container (not mycontrol)
>>has never been raised. I had tested something and found that:
>> If I set like this : Set MyControl1.Datasource.Tablesource.Table
>=
>>Grid <-- msflexgrid
>>
>> << code within Property Table>>
>> Dim m_objFlex as MSFlexGrid
>> Public Set Property Table(Byval vData as Object)
>> Set m_objFlex = vData
>> End Property
>> << >>
>>My web-app has never been shut-down. If I didn't set this property, it
>>can terminate properly. Unfortunately, I have to use MSFlexGrid as a
datasource
>>for my control, and I need to let my control to work on MSFlexGrid; such
>>as fill data, or change color in MSFlexGrid.
>>
>> I try to set m_objFlex to nothing before closing the Web, it can
terminate
>>properly. Unfortunately, I can't track when user needs to close the Web.
>> Indeed, the Web should be terminated properly when user closed the Web.
>> That's the problem. How can I solve this problem?
>>
>>Thank you
>>Rattagarn V.
>
Re: Usercontrol's never been terminated
Rattagarn,
I would need more info. Simplify the control so that you get the same problem
and post this code
Michael Culley
"Rattagarn V" <rattagarn@hotmail.com> wrote:
>
>Hi
>
> Thank you for Micheal Culley's reponse and his last good tip.
>
>I tried to use your solution with the problem I got. Unfortunately, it
didn't
>work. Now I have no problem about Parent/Child circular reference. I tested
>this by implementing a small active X project and has the parent/child relationships.
> It runs and shutdown properly. Unintentionally, I found the another error
>which probably caused the shutdown problem of the control. It is my last
>posted message. So I used your solution as I told, but it didn't work.
>
>What should I deal with this problem?
>
>Best Regards
>Rattagarn V.
>
>"Michael Culley" <m_culley@one.net.au> wrote:
>>
>>Rattagarn,
>>
>>I remember answering this question before. Didn't my previous suggestion
>>work?
>>
>>Michael Culley
>>
>>
>>"Rattagarn V." <rattagarn@hotmail.com> wrote:
>>>
>>>Hi all,
>>>
>>> I create an ActiveX control which needs to link with MSFlexGrid.
>This
>>>is my component model:
>>>
>>> MyControl (usercontrol)
>>> |
>>> +------ Datasource (Get Property () as CDatasrc class)
>>> |
>>> + ---- Tablesource (Get Property ()
as
>>>CTable class)
>>> |
>>> + ----- Table (Set
>>>Property (Byval vData as Object)
>>>
>>> I attached my control on the another usercontrol (as Web container),
>>>because I would like to create Web application.
>>>
>>>The problem is that it wouldn't been terminated when user closed IE.
I
>>mean
>>>that Usercontrol_Terminated event of Usercontrol container (not mycontrol)
>>>has never been raised. I had tested something and found that:
>>> If I set like this : Set MyControl1.Datasource.Tablesource.Table
>>=
>>>Grid <-- msflexgrid
>>>
>>> << code within Property Table>>
>>> Dim m_objFlex as MSFlexGrid
>>> Public Set Property Table(Byval vData as Object)
>>> Set m_objFlex = vData
>>> End Property
>>> << >>
>>>My web-app has never been shut-down. If I didn't set this property,
it
>>>can terminate properly. Unfortunately, I have to use MSFlexGrid as a
>datasource
>>>for my control, and I need to let my control to work on MSFlexGrid; such
>>>as fill data, or change color in MSFlexGrid.
>>>
>>> I try to set m_objFlex to nothing before closing the Web, it can
>terminate
>>>properly. Unfortunately, I can't track when user needs to close the Web.
>>> Indeed, the Web should be terminated properly when user closed the Web.
>>> That's the problem. How can I solve this problem?
>>>
>>>Thank you
>>>Rattagarn V.
>>
>
Re: Usercontrol's never been terminated
Thank you very much Michael and sorry for late response:
This is the object model of my control:
////////////////////////////////////////////////////////////////////////////////////
[Project 1]
MyControl
|
+--- BackColor (property)
+--- BoxIndex (property)
+--- Pack (property/return class CPack)
|
+--- Name (property)
+--- LoadDataFromFlex (method)
+--- Datasource (property/set to link MSFlexGrid)
+--- Boxes (property/return class CBoxes)
|
+--- Item (property/return class CBox)
|
+-- Data (property)
+-- Parent (property/refer to its parent, CPack)
This is the code for my control:
CBox class module (Public not creatable):
= = = = = = = = = = = =
Option Explicit
Dim m_objParent As CPack '<< reference to parent
Dim m_lobj As Long
Dim m_szData As String
Public Property Let Data(ByVal vData As String)
m_szData = vData
End Property
Public Property Get Data() As String
Data = m_szData
End Property
Friend Property Set Parent(ByVal vData As CPack)
If Not vData Is Nothing Then
m_lobj = ObjPtr(vData)
Set m_objParent = ResolveObjPtr(m_lobj)
End If
End Property
Private Sub Class_Terminate()
Set Me.Parent = Nothing
End Sub
Private Function ResolveObjPtr(ByVal Pointer As Long) As Object
Dim x As Object
CopyMemory x, Pointer, 4&
Set ResolveObjPtr = x
CopyMemory x, 0&, 4&
End Function
=====================================================
CBoxes class module (Public not creatable, collection of CBox):
= = = = = = = = = = = = =
Option Explicit
Dim m_cColl As Collection
Private Sub Class_Initialize()
Set m_cColl = New Collection
End Sub
Private Sub Class_Terminate()
Set m_cColl = Nothing
End Sub
Friend Sub Add(ByVal ObjParent As Object, ByVal Data As String)
Dim m_cBox As New CBox
Set m_cBox.Parent = ObjParent
m_cBox.Data = Data
m_cColl.Add m_cBox
End Sub
Friend Property Get Count() As Long
Count = m_cColl.Count
End Property
Public Property Get Item(Index) As CBox
Set Item = m_cColl(Index)
End Property
Friend Sub Remove(Index)
m_cColl.Remove Index
End Sub
Public Property Get NewEnum() As IUnknown
Set NewEnum = m_cColl.[_NewEnum]
End Property
=====================================================
CPack class module (Public not creatable)
= = = = = = = = = = = = =
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst
As Any, pSrc As Any, ByVal ByteLen As Long)
Dim m_szName As String
Dim m_objFlex As MSFlexGrid
Dim m_cBoxes As CBoxes
Dim m_lFlexObj As Long
Public Property Let Name(ByVal vData As String)
m_szName = vData
End Property
Public Property Get Name() As String
Name = m_szName
End Property
Private Sub Class_Initialize()
Set m_cBoxes = New CBoxes
End Sub
Private Sub Class_Terminate()
Set m_cBoxes = Nothing
Set Me.Datasource = Nothing
End Sub
Public Property Get Boxes() As CBoxes
Set Boxes = m_cBoxes
End Property
Public Property Set Datasource(ByVal vData As Object)
m_lFlexObj = ObjPtr(vData)
Set m_objFlex = ResolveObjPtr(m_lFlexObj)
End Property
Private Function ResolveObjPtr(ByVal Pointer As Long) As Object
Dim x As Object
CopyMemory x, Pointer, 4&
Set ResolveObjPtr = x
CopyMemory x, 0&, 4&
End Function
Public Sub LoadDataFromFlex()
Dim i As Long
Dim j As Long
Dim n As Long
For i = 1 To m_objFlex.Rows - 1
For j = 1 To m_objFlex.Cols - 1
n = n + 1
m_cBoxes.Add Me, m_objFlex.TextMatrix(i, j)
Next j
Next i
End Sub
====================================================
MyControl usercontrol module
= = = = = = = = = = = = = = = = = =
Option Explicit
Dim m_lBkColor As Long
Dim m_lIndex As Long
Dim m_cPack As CPack
Private Sub UserControl_Initialize()
Debug.Print "MyControl is initialized"
Set m_cPack = New CPack
m_lBkColor = &HFFFFFF
m_lIndex = 1
End Sub
Private Sub UserControl_Paint()
UserControl.BackColor = m_lBkColor
UserControl.Line (5, 5)-(UserControl.ScaleWidth - 10, UserControl.ScaleHeight
- 10), &HFFC0C0, B
UserControl.CurrentX = 100
UserControl.CurrentY = 100
If m_cPack.Boxes.Count > 0 Then
If m_lIndex > m_cPack.Boxes.Count Then m_lIndex = 1
UserControl.Print m_cPack.Boxes(m_lIndex).Data
End If
End Sub
Private Sub UserControl_Terminate()
Set m_cPack = Nothing
Debug.Print "MyControl is terminated properly"
End Sub
Public Property Let BackColor(ByVal vData As Long)
m_lBkColor = vData
End Property
Public Property Get BackColor() As Long
BackColor = m_lBkColor
End Property
Public Property Get Pack() As CPack
Set Pack = m_cPack
End Property
Public Property Let BoxIndex(ByVal vData As Long)
m_lIndex = vData
Refresh
End Property
Public Property Get BoxIndex() As Long
BoxIndex = m_lIndex
End Property
=================================================
////////////////////////////////////////////////////////////////////////////////////
[Project 2]
This project is the another usercontrol as Webpage which contains my control
, MSFlexGrid, and etc:
Label1, Label2, txtRows, txtCols, Flex, cmdLoadToBox, cmdGen, chkLinkFlex,
cmdGetBox, txtBoxIndex, and MyControl1.
The code for this web:
Option Explicit
Private Sub chkLinkFlex_Click()
'// set datasource for the control
If chkLinkFlex.Value = 1 Then
Set MyControl1.Pack.DataSource = Flex
Else
Set MyControl1.Pack.DataSource = Nothing
End If
End Sub
Private Sub cmdGen_Click()
'// set data for MSFlexGrid
Dim i As Long
Dim j As Long
Flex.Rows = CLng(txtRows.Text)
Flex.Cols = CLng(txtCols.Text)
For i = 1 To Flex.Rows - 1
For j = 1 To Flex.Cols - 1
Flex.TextMatrix(i, j) = Format(Rnd() * 100, "#0.00")
Next j
Next i
End Sub
Private Sub cmdGetBox_Click()
'// set Index of Box in Boxes for getting its data and display on MyControl
MyControl1.BoxIndex = CLng(txtBoxIndex)
End Sub
Private Sub cmdLoadToBox_Click()
'// call function LoadDataFromFlex for creating instances of CBox and add
them to CBoxes collection
MyControl1.Pack.LoadDataFromFlex
End Sub
Private Sub UserControl_Terminate()
MsgBox "Terminate"
End Sub
=================================================
After running my code, I found that Terminate event has never been raised.
Thank you very much and appologize for disturbing you.
Rattagarn V.
"Michael Culley" <m_culley@one.net.au> wrote:
>
>Rattagarn,
>
>I would need more info. Simplify the control so that you get the same problem
>and post this code
>
>Michael Culley
Re: Usercontrol's never been terminated
Hi all,
Can anyone give me the solution for this problem?
Thank you very much
"Rattagarn V" <rattagarn@hotmail.com> wrote:
>
>Thank you very much Michael and sorry for late response:
>
>This is the object model of my control:
>////////////////////////////////////////////////////////////////////////////////////
>[Project 1]
>MyControl
> |
> +--- BackColor (property)
> +--- BoxIndex (property)
> +--- Pack (property/return class CPack)
> |
> +--- Name (property)
> +--- LoadDataFromFlex (method)
> +--- Datasource (property/set to link MSFlexGrid)
> +--- Boxes (property/return class CBoxes)
> |
> +--- Item (property/return class CBox)
> |
> +-- Data (property)
> +-- Parent (property/refer to its parent, CPack)
>
>This is the code for my control:
>
>CBox class module (Public not creatable):
>= = = = = = = = = = = =
>Option Explicit
>
>Dim m_objParent As CPack '<< reference to parent
>Dim m_lobj As Long
>Dim m_szData As String
>
>Public Property Let Data(ByVal vData As String)
> m_szData = vData
>End Property
>
>Public Property Get Data() As String
> Data = m_szData
>End Property
>
>Friend Property Set Parent(ByVal vData As CPack)
> If Not vData Is Nothing Then
> m_lobj = ObjPtr(vData)
> Set m_objParent = ResolveObjPtr(m_lobj)
> End If
>End Property
>
>Private Sub Class_Terminate()
> Set Me.Parent = Nothing
>End Sub
>
>Private Function ResolveObjPtr(ByVal Pointer As Long) As Object
>Dim x As Object
> CopyMemory x, Pointer, 4&
> Set ResolveObjPtr = x
> CopyMemory x, 0&, 4&
>End Function
>=====================================================
>
>CBoxes class module (Public not creatable, collection of CBox):
>= = = = = = = = = = = = =
>Option Explicit
>
>Dim m_cColl As Collection
>
>Private Sub Class_Initialize()
> Set m_cColl = New Collection
>End Sub
>
>Private Sub Class_Terminate()
> Set m_cColl = Nothing
>End Sub
>
>Friend Sub Add(ByVal ObjParent As Object, ByVal Data As String)
>Dim m_cBox As New CBox
> Set m_cBox.Parent = ObjParent
> m_cBox.Data = Data
> m_cColl.Add m_cBox
>End Sub
>
>Friend Property Get Count() As Long
> Count = m_cColl.Count
>End Property
>
>Public Property Get Item(Index) As CBox
> Set Item = m_cColl(Index)
>End Property
>
>Friend Sub Remove(Index)
> m_cColl.Remove Index
>End Sub
>
>Public Property Get NewEnum() As IUnknown
> Set NewEnum = m_cColl.[_NewEnum]
>End Property
>=====================================================
>
>CPack class module (Public not creatable)
>= = = = = = = = = = = = =
>Option Explicit
>
>Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst
>As Any, pSrc As Any, ByVal ByteLen As Long)
>
>Dim m_szName As String
>Dim m_objFlex As MSFlexGrid
>Dim m_cBoxes As CBoxes
>Dim m_lFlexObj As Long
>
>Public Property Let Name(ByVal vData As String)
> m_szName = vData
>End Property
>
>Public Property Get Name() As String
> Name = m_szName
>End Property
>
>Private Sub Class_Initialize()
> Set m_cBoxes = New CBoxes
>End Sub
>
>Private Sub Class_Terminate()
> Set m_cBoxes = Nothing
> Set Me.Datasource = Nothing
>End Sub
>
>Public Property Get Boxes() As CBoxes
> Set Boxes = m_cBoxes
>End Property
>
>Public Property Set Datasource(ByVal vData As Object)
> m_lFlexObj = ObjPtr(vData)
> Set m_objFlex = ResolveObjPtr(m_lFlexObj)
>End Property
>
>Private Function ResolveObjPtr(ByVal Pointer As Long) As Object
>Dim x As Object
> CopyMemory x, Pointer, 4&
> Set ResolveObjPtr = x
> CopyMemory x, 0&, 4&
>End Function
>
>Public Sub LoadDataFromFlex()
>Dim i As Long
>Dim j As Long
>Dim n As Long
> For i = 1 To m_objFlex.Rows - 1
> For j = 1 To m_objFlex.Cols - 1
> n = n + 1
> m_cBoxes.Add Me, m_objFlex.TextMatrix(i, j)
> Next j
> Next i
>End Sub
>====================================================
>
>MyControl usercontrol module
>= = = = = = = = = = = = = = = = = =
>Option Explicit
>
>Dim m_lBkColor As Long
>Dim m_lIndex As Long
>Dim m_cPack As CPack
>
>Private Sub UserControl_Initialize()
> Debug.Print "MyControl is initialized"
> Set m_cPack = New CPack
> m_lBkColor = &HFFFFFF
> m_lIndex = 1
>End Sub
>
>Private Sub UserControl_Paint()
> UserControl.BackColor = m_lBkColor
> UserControl.Line (5, 5)-(UserControl.ScaleWidth - 10, UserControl.ScaleHeight
>- 10), &HFFC0C0, B
> UserControl.CurrentX = 100
> UserControl.CurrentY = 100
> If m_cPack.Boxes.Count > 0 Then
> If m_lIndex > m_cPack.Boxes.Count Then m_lIndex = 1
> UserControl.Print m_cPack.Boxes(m_lIndex).Data
> End If
>End Sub
>
>Private Sub UserControl_Terminate()
> Set m_cPack = Nothing
> Debug.Print "MyControl is terminated properly"
>End Sub
>
>Public Property Let BackColor(ByVal vData As Long)
> m_lBkColor = vData
>End Property
>
>Public Property Get BackColor() As Long
> BackColor = m_lBkColor
>End Property
>
>Public Property Get Pack() As CPack
> Set Pack = m_cPack
>End Property
>
>Public Property Let BoxIndex(ByVal vData As Long)
> m_lIndex = vData
> Refresh
>End Property
>
>Public Property Get BoxIndex() As Long
> BoxIndex = m_lIndex
>End Property
>=================================================
>
>////////////////////////////////////////////////////////////////////////////////////
>[Project 2]
>This project is the another usercontrol as Webpage which contains my control
>, MSFlexGrid, and etc:
>Label1, Label2, txtRows, txtCols, Flex, cmdLoadToBox, cmdGen, chkLinkFlex,
>cmdGetBox, txtBoxIndex, and MyControl1.
>
>The code for this web:
>
>Option Explicit
>
>Private Sub chkLinkFlex_Click()
>'// set datasource for the control
> If chkLinkFlex.Value = 1 Then
> Set MyControl1.Pack.DataSource = Flex
> Else
> Set MyControl1.Pack.DataSource = Nothing
> End If
>End Sub
>
>Private Sub cmdGen_Click()
>'// set data for MSFlexGrid
>Dim i As Long
>Dim j As Long
> Flex.Rows = CLng(txtRows.Text)
> Flex.Cols = CLng(txtCols.Text)
> For i = 1 To Flex.Rows - 1
> For j = 1 To Flex.Cols - 1
> Flex.TextMatrix(i, j) = Format(Rnd() * 100, "#0.00")
> Next j
> Next i
>End Sub
>
>Private Sub cmdGetBox_Click()
>'// set Index of Box in Boxes for getting its data and display on MyControl
> MyControl1.BoxIndex = CLng(txtBoxIndex)
>End Sub
>
>Private Sub cmdLoadToBox_Click()
>'// call function LoadDataFromFlex for creating instances of CBox and add
>them to CBoxes collection
> MyControl1.Pack.LoadDataFromFlex
>End Sub
>
>Private Sub UserControl_Terminate()
> MsgBox "Terminate"
>End Sub
>=================================================
>
>After running my code, I found that Terminate event has never been raised.
>
>Thank you very much and appologize for disturbing you.
>
>Rattagarn V.
>
>"Michael Culley" <m_culley@one.net.au> wrote:
>>
>>Rattagarn,
>>
>>I would need more info. Simplify the control so that you get the same problem
>>and post this code
>>
>>Michael Culley
>
>