|
-
Jan 9th, 2011, 12:54 PM
#14
Re: [RESOLVED] [VB6] - about properties
 Originally Posted by joaquim
thanks. beause i have seen that if i use strFileName, it can't save the value, but if i use FileName, save it.
we must use the same for writeproperties?
That's not true. Either 1) you are setting strFileName to something else somewhere else in your code, or 2) you are not processing the file when your Show event is called.
Code:
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "FileName", strFileName, vbNullString
end sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
strFileName = PropBag.ReadProperty("FileName", vbNullString)
end sub
Look at your previous thread, post #9, regarding the Show event.
As a rule, you load all your properties into their uc-level variables. Once you get your uc Show event, then you create what is needed, resize if needed, and paint your uc. As it is now, it appears many of your properties do a bunch of processing. Since you are not calling your property by reading the propertybag value into the variable, the code in the property LET isn't run. You wrote your properties incorrectly in my opinion. The code in the properties should not modify your control. Rather, it should call other routines that modify the control. This way, when the the Show event is first called, it could call those same routines.
If you are going to leave it the way it was and call your Property names when reading from the propertybag, then there are downsides as I mentioned before: 1) The control, when closing, will re-save all of its properties even if no properties changed. This is because in each of those properties you are calling, there is a PropertyChanged being triggered. 2) If any of those properties refer to its parent, extender, or ambient properties, it is possible the control is not sited during ReadProperties event, and you'll get an error. In that case you'll have to add error trapping, but the control probably won't be displayed anyway because of the errors. The control will always be sited during the Show event.
 Originally Posted by Dan Appleman
To be sited on a container. This means the control has its own independent user interface that is contained on the window of another application, be it a form in Visual Basic or a Web page on an Internet browser. The control is able to interact with the container application in a variety of different ways.
 Originally Posted by Dan Appleman
... during the Show event, during which it is safe to assume (at least with Visual Basic) that all of the other controls belonging to the container have already been sited.
 Originally Posted by Dan Appleman
During the INITIALIZE event you may not:
Access the Extender or Ambient properties of the UserControl object or any
of their properties. This is because while your control object does exist at
this time, it has not yet been placed on the container (or, as they usually
phrase it, the control has not yet been sited at this time).
 Originally Posted by Dan Appleman
During the INITPROPERTIES event you should not:
- Display anything. The control will not yet be visible at this time.
- Perform operations that depend on the size of the control. The control and
container may not yet be at their final size.
- Perform operations that assume that the control window is actually present
on the container. Examples of these include API functions that manipulate
windows. The control window is not actually on the container during this
event (though from the point of view of the object relationships, it has
already been sited).
 Originally Posted by Dan Appleman
During the READPROPERTIES event you may:
- Perform most of the initializations that depend on the container. The control
is already sited when this event occurs, thus the Extender and Ambient
properties are valid.
During this event you should not:
- Display anything. The control will not yet be visible at this time.
- Perform operations that depend on the size of the control. The control and
container may not yet be at their final size.
- Perform operations that assume that the control window is actually present
on the container. Examples of these include API functions that manipulate
windows. The control window is not actually on the container during this
event (though from the point of view of the object relationships, it has
already been sited).
Note about above. When control is displayed in another environment (not Visual Basic), I have experienced errors when trying to access Ambient/Extender properties. I have never had this problem in Visual Basic thought.
 Originally Posted by Dan Appleman
During the SHOW event you may:
- Perform any operations that you would like a Web-based control to do when
the user returns to the page containing the control.
- Set a flag variable to indicate that your control has, in fact, been sited on a
container. Some development environments do not site controls at design
time. This will be discussed further in the section describing the Paint event.
- When this event occurs (at least on VB5), all of the other controls on a form are sited and the form's Load event has executed. This differs from the
ReadProperties event, which guarantees only that your control is sited. If
your control must interact with other controls on a form (which is not
recommended), this is probably a safe time to do so, though this behavior is
not guaranteed for every container.
And here's the link again to Dan Appleman's book:
http://www.google.com/url?sa=t&sourc...rtotVtf8Uj3F5w
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
|