|
-
May 17th, 2000, 10:40 PM
#1
Thread Starter
Member
Ok, I need help! This has had me & the rest of the office stumpted all afternoon.
What I'm basically trying to implement is funcionality the same as exhibited by Word's 'Find', i.e. a form ('B') is spawned non-modally by the main form ('A'). Both 'A' and 'B' can respond to user actions (editing or whatever). 'B' contains a button 'Cancel' or something similar that kills it. The only problem is that somewhere there's a reference hanging round, because the form 'B' NEVER terminates!
Has anyone written anything like this or have any idea how to go about it? Please help!!
K
[Edited by kleve on 05-18-2000 at 04:59 PM]
-
May 18th, 2000, 02:10 AM
#2
Lively Member
I'm not sure what you're asking here.. At the top, you talk about creating some "find" functionality.. then you talk about 2 forms.. then you talk about form B not exiting. You sounded like it's a problem that form "b" doesn't exit, but then you ask if anyone knows how to do it. Where does the "find" functionality come into play? are you trying to have form b exit or really not exit? Sorry.. but your post is a little confusing and that's probably why no one has responded..
-
May 18th, 2000, 02:56 PM
#3
Thread Starter
Member
Sorry if I sounded confused, It's hard to explain something when you've been immersed in it for a while.
I'm not looking to implement a find (well, I am, but that bit works).
What I'm trying to do is re-create the way that Word has a separate find box that is always on top of the document but not modal, i.e. both the document form and the find form can both have focus and can both accept user interaction.
This is fine and works well, my problem is when it comes to destroy the find form. I create an instance of it by doing
Code:
'Create it
Set formFind = New frmFind
'load it
Load formFind
'Set always on top
SetWin formMove, HWND_TOPMOST
'Show it
formMove.Show
When the user clicks the 'Close' button on the find form, the form does a form unload and unloads. It then carries on executing the rest of the code in the cmdClose button.
When the form that spawns it unloads, it sets the reference to the find form to Nothing but the program doesn't die. I know it's that form because I've run everything else, just skipped creating the find form and the program ends correctly. The form doesn't create anything, so it can't be anything on the form thats set to nothing.
I can force the issue with an 'End' but being pedantic, I'd like to get it to work 'properly' 
Thanks
K
-
May 18th, 2000, 03:16 PM
#4
Hello,
I belive your problem is comming from the "SetWin formMove, HWND_TOPMOST" section. I had a simulare problem once with a splash screen. Before you unload the frmFind you need to change it back to a a normal window again. And then it will unload with aout any problem.
Hope this helps,
[Edited by RvA on 05-19-2000 at 04:17 AM]
-
May 18th, 2000, 03:39 PM
#5
Thread Starter
Member
Thanks RvA, but I'm afraid that's not it :/
I tried setting it back to normal and just not setting to always on top but neither seem to make any difference.
Like I said it unloads fine but it never runs the terminate event. That indicates to me (after hard experience with ActiveX stuff) that somewhere there's a reference to it hanging around. I know I've certainly not created one expicitly, so unless I've got an implicit reference somewhere, I really don't know what's going on.
As an aside, does anyone know a tool that will let you watch the number of references to something? I suspect such a tool would help me at the moment 
Cheers,
K
-
May 18th, 2000, 03:44 PM
#6
OK then, what if you use a "set frmFind = Nothing" in the frmFind "Unload" section? maybe that will kill the beast.
-
May 18th, 2000, 03:49 PM
#7
Thread Starter
Member
Tried that too :/
No matter what I do to kill it, if I step through the code it always goes back to the code at the end of the cmdClose button.
Cheers
K
-
May 18th, 2000, 03:52 PM
#8
Also on the VB6 Pro rom I found three tools that might help you. Look in the following Folders:
1) \Common\Tools\VB\PSpy
2) \Common\Tools\VB\PView
3) \Common\Tools\VB\Spy
I sure one of those will work.
Hope this helps,
-
May 18th, 2000, 04:02 PM
#9
Well then you've stumped me too.....
Sorry I couldn't be more help
-
May 18th, 2000, 07:10 PM
#10
Lively Member
OK... this may not be correct but this is what I uderstand. You have a form that has a close button.
The close button first unloads the for it's on and then
executes other commands?
If this is the case, I'd think it was your problem. Your command button is part of the form, and you're unloading the form.. but there's more code after it to execute. So it really can't unload.
If you need to make the form not visable before you execute this other code, hide it first, then execute your code, then unload it. If not, execute your code first, then the last thing in that event should be the unload.
Sorry if this answer doesn't refelect the functionality in your program. It's what I interpreted and I thought I'd write an asnwer to it instead of asking if I was correct first
-
May 18th, 2000, 07:53 PM
#11
Thread Starter
Member
Thank you! It works!!
Now, why should I have to hide the form to get it to unload? Sorry is this is a bit basic but I've never heard of having to do that before!
K
-
May 18th, 2000, 08:22 PM
#12
Lively Member
hiding the form didn't do it. Having the last thing the button does be unloading the form is what did it. Think of it this way..
All the code in your form is essentially part of the form. If you unload it, you can't execute the code in it. So having a function that does the following..
Code:
Unload Me
MainForm.Visable = True
Is a problem waiting to happen. You're telling the form to unload but you have code in that form that's still waiting to execute. I can't say speciffically what will happen if this is done but I'd guess that either
a) The part after the Unload isn't going to happen.. or
b) the form is going to try to unload and cancel because
there's still code to execute.
You don't have to specifically hide the form but if you want to make the form not visable while something else happens then you may want to..
In the above example, the correct way to do it would be
Code:
MainForm.Visable = True
Unload Me
but that will make the main form visable and then make the sub form go away. That may not be the visual effect that you want.. so you'd do..
Code:
Me.Hide
MainForm.Visable = True
Unload Me
Let me know if this answered your question...
-
May 18th, 2000, 09:02 PM
#13
Thread Starter
Member
I'm afraid to say that I've probably wasted peoples time with my own stupidity 
It's neither the hide or the being the last line of code in the form, it was one of the lines after the unload command. I had some code to check a property on the main form (no problems there) and enable/disable a command button on the find form depending on the property. Can we all guess what was going on? I was dead right about it being a reference hanging round, and an implicit one too. When I referenced the command button to set it's status it created an implicit reference to the form and bang, there we go.
My problem was I was fixing a bug in some legacy code (when clicking the close find box the whole app would quit) and the close button and the other buttons on the form were in a control array. I'd prefer separate buttons but hey, that's the way it was.
If anyone's bothered, the offending code is below
Code:
Select Case Index
Case 0
formMain.MoveBack
Case 1
formMain.MoveForward
Case 2
formMain.StopFind
Case 3
formMain.UpdateText
End Select
If formMain.TextSelectedStatus Then
'Doh!! Lets create a reference to the thing we're trying to kill
cmdFind(3).Enabled = True
Else
'Doh!! Lets create a reference to the thing we're trying to kill
cmdFind(3).Enabled = False
End If
Sorry to have been a pain 
K
-
May 18th, 2000, 11:45 PM
#14
Cool I'm glad you found it good job!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|