Re: Surprised to see UserControls Executing During Compilation!
- From: "Joseph Geretz" <jgeretz@xxxxxxxxxx>
- Date: Tue, 13 Jun 2006 15:31:33 -0400
Hi Guys,
Very interesting.
Ambient.UserMode is useful for a control which is directly hosted in the
form which is open in the IDE. Any nested controls though, will see an
Ambient.UserMode of False. Arguably this will be OK in many situations.
However, if you need to know absoluately whether you are running inside the
IDE (for example, you need to determine whether or not to set up
subclassing) then Ambient.UserMode is insufficient. We use our own RunMode
utility function (below) to make this determination.
Also, Ambient.UserMode doesn't distinguish between Design Time and Compile
Time. Again, arguably, is this even necessary? In most cases, no - according
to my experience. A case where this might be necessary is where the
UserControl is hosted on a Form within the project in which it is defined.
What has me baffled is, with nested controls I see the ReadProperties event
firing for both the inner and outer controls when the host application is
compiled. What's that about? As far as I know, it's the responsibility of
the Outer control to bag all properties. I guess though, that each nested
control is responsible for its own DEFAULT properties?
Try that. It'll pop while the toolbar says "Writing EXE..." only when the
designer for the form isn't open.
I guess this is because, since the host form is not open, the UserControl
properties haven't been initialized and so this has to be explicitly done at
this point.
If the form designer _is_ open, it
doesn't pop until the EXE has been fully committed to disk. I honestly
can't begin to offer an explanation for that pattern.
I guess we can speculate about why it doesn't pop while the compiler is
writing the executable. Since the host form is open, the properties are
presumed to be initialized and so it's not necessary. The pop you describe,
probably has more to do with refreshing the form in the IDE after the
compile is complete, rather than part of the compilation itself. (BTW, in a
simple project with a single form, I don't see this pop at all, following a
compile.)
Thanks for your input. I now have a better understanding about why code is
executing during compilaton. However, nested controls aren't as
traightforward as simple controls. This whole issue bears further
investigation. If I put together a prototype or something, I'll report back
here. I guess I've been getting away with this for years because the default
behavior is sufficient for us. It would be nice though, to know *exactly*
what to expect under the complete variety of possible scenarios.
Thanks!
- Joe Geretz -
Public Function RunMode(HWnd As Long, _
Optional Designer As String = "VB6.EXE") _
As SRSRunMode
Dim ModuleName As String
Dim filename As String
Dim hInst As Long
Dim Ret As Long
ModuleName = String$(128, Chr$(0))
hInst = GetWindowWord(HWnd, GWW_HINSTANCE)
ModuleName = Left$(ModuleName, GetModuleFileName(hInst, ModuleName,
Len(ModuleName)))
RunMode = DesignTime
If (Len(ModuleName)) > 0 Then
If InStr(1, ModuleName, Designer, vbTextCompare) = 0 Then
RunMode = RunTime
End If
End If
End Function
"Karl E. Peterson" <karl@xxxxxxxx> wrote in message
news:uzOUfhwjGHA.1936@xxxxxxxxxxxxxxxxxxxxxxx
Michael C wrote:
"Karl E. Peterson" <karl@xxxxxxxx> wrote in message
news:uSJ87ZnjGHA.3620@xxxxxxxxxxxxxxxxxxxxxxx
Joseph Geretz wrote:
I can tell the difference between design time and run-time, but is
there any way to tell when my control is being compiled, or is
running within a host which is undergoing compilation?
I guess I'd be surprised, as well. What did you see that led you to
ask this question?
This is suprising, vb instantiates usercontrols during compile and
executes readproperties events etc.
As a generality, that's pretty simple to refute...
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
MsgBox "UserControl_ReadProperties", , Ambient.UserMode
End Sub
Try that. It'll pop while the toolbar says "Writing EXE..." only when the
designer for the form isn't open. If the form designer _is_ open, it
doesn't pop until the EXE has been fully committed to disk. I honestly
can't begin to offer an explanation for that pattern.
The solution is to use Ambient.UserMode.
Again, that reads False in both compilation scenarios above, just as it
does
when opening the form designer in the IDE. Seems totally useless as a
means
of distinguishing this special circumstance.
--
Working without a .NET?
http://classicvb.org/
.
- Follow-Ups:
- Re: Surprised to see UserControls Executing During Compilation!
- From: Karl E. Peterson
- Re: Surprised to see UserControls Executing During Compilation!
- References:
- Surprised to see UserControls Executing During Compilation!
- From: Joseph Geretz
- Re: Surprised to see UserControls Executing During Compilation!
- From: Karl E. Peterson
- Re: Surprised to see UserControls Executing During Compilation!
- From: Michael C
- Re: Surprised to see UserControls Executing During Compilation!
- From: Karl E. Peterson
- Surprised to see UserControls Executing During Compilation!
- Prev by Date: Re: Treeview (Common Controls 6.0 (SP6)) node.checked issue
- Next by Date: Re: Surprised to see UserControls Executing During Compilation!
- Previous by thread: Re: Surprised to see UserControls Executing During Compilation!
- Next by thread: Re: Surprised to see UserControls Executing During Compilation!
- Index(es):
Relevant Pages
|