Re: Surprised to see UserControls Executing During Compilation!



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/




.



Relevant Pages

  • Re: How Can I disable autosaving when quitting Access?
    ... The compile option is disabled, I thought you could only compile if you're ... Doug Steele, Microsoft Access MVP ... that some of the controls are unboud such as the date pickers is because ... There are a few other anomalies of the sort (iCheck ...
    (microsoft.public.access.formscoding)
  • Re: VB6 - Out of memory error opening form in IDE
    ... view of the form or compile the project, I get the out of memory error. ... The project has been worked on and compiled numerous times in ... If you're using controls from a 3rd party vendor, add them back to that new ...
    (microsoft.public.vb.general.discussion)
  • Re: Urgent: Controls disapearing from Design Surface...
    ... IF the controls that are disappearing are user defined (that is, ... controls doesn't compile, then the Designer may remove them from the ... them on the design surface, the Designer has to have a compiled DLL ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • ASP.NET Compiler Behavior Affected by the Page Content?
    ... I've been struggling with some issues relating to referencing child controls ... and working and in that code, he references child controls within a FormView ... This code will not compile because MyComment is not a valid property. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Compile errors after converting to a Web Application Project from
    ... there are more restrictions on code sharing (web site compile ... partial classes (basically declaring server controls as protected global). ... i have never seen an advantage to switch to web applications, ... found at "Converting a Web Site Project to a Web Application Project". ...
    (microsoft.public.dotnet.framework.aspnet)