-
Feb 8th, 2018, 12:28 PM
#1
To write UserControl's properties at any given time?
The UserControls properties are saved in the WriteProperties event, and it fires only when the form is closed in the designer.
The problem is that when it is used within an standard exe project, if the developer opens the Usercontrol's designer window, all the instances of the UserControl that are on forms lose their changed properties settings.
Is there any way to force to write the properties at any given time.
I guess not, but it doesn't cost me anything to ask.
-
Feb 8th, 2018, 12:56 PM
#2
Re: To write UserControl's properties at any given time?
It's also called when the form is saved to disk. Not sure if that helps though.
If you want to see this, just right-click and "Save" any form with your UC on it (and have a debug.print in the WriteProperties event). It always fires when the form is saved.
Also ...
Originally Posted by Eduardo-
The problem is that when it is used within an standard exe project, if the developer opens the Usercontrol's designer window, all the instances of the UserControl that are on forms lose their changed properties settings.
... I don't seem to have that problem. Here's code I put into a UC for testing:
Code:
Option Explicit
'
Dim mlASDF As Long
'
Public Property Get asdf() As Long
asdf = mlASDF
End Property
Public Property Let asdf(l As Long)
mlASDF = l
PropertyChanged "asdf"
End Property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
mlASDF = PropBag.ReadProperty("asdf", 0&)
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Debug.Print "WriteProperties"
PropBag.WriteProperty "asdf", mlASDF
End Sub
And then, I threw that UC onto a Form1, set the asdf property to 5 in the Properties Window, and then opened the UC, messed with it, closed it, and the Form1 still showed asdf=5. So, I'm confused.
All The Best,
Elroy
EDIT1: Also, my main project has tons of UCs used on it, and I do occasionally tweak them. And I've never had a problem with custom property values disappearing. In one control in particular, I do have a bit of trouble with a RTB that's on the UC, but that's really a separate issue. All works fine so long as I don't tamper with things. It's just some minor bug I've never tracked down.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Feb 8th, 2018, 02:25 PM
#3
Re: To write UserControl's properties at any given time?
Originally Posted by Elroy
It's also called when the form is saved to disk. Not sure if that helps though.
If you want to see this, just right-click and "Save" any form with your UC on it (and have a debug.print in the WriteProperties event). It always fires when the form is saved.
Sorry, but that solves nothing, Elroy.
The developer will never remember to do that before opening the UserControl's designer window.
BTW: I'm quite used to close the forms before opening an UserControl's designer because of that problem, but I don't always remember to do so either.
Originally Posted by Elroy
Also ...
... I don't seem to have that problem. Here's code I put into a UC for testing:
Code:
Option Explicit
'
Dim mlASDF As Long
'
Public Property Get asdf() As Long
asdf = mlASDF
End Property
Public Property Let asdf(l As Long)
mlASDF = l
PropertyChanged "asdf"
End Property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
mlASDF = PropBag.ReadProperty("asdf", 0&)
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Debug.Print "WriteProperties"
PropBag.WriteProperty "asdf", mlASDF
End Sub
And then, I threw that UC onto a Form1, set the asdf property to 5 in the Properties Window, and then opened the UC, messed with it, closed it, and the Form1 still showed asdf=5. So, I'm confused.
I have exactly the opposite experience.
If I do that, to set the property to 5, then open the UserControl's designer window, close it. The 5 is gone, the property is back to its prior value.
Also, I mean the visual designer, not the UserControl's code window.
If you open the code window and don't change the code, there is no problem. But if you change the UserControl's code in any way, the problem also happens.
-
Feb 8th, 2018, 03:34 PM
#4
Re: To write UserControl's properties at any given time?
Wow, using my example above, I had my Form1 open. Then, I opened the UC (designer) and placed a new label on this UC. While doing that, it hatched-out the UC on Form1, but that's to be expected. But when I close the UC's designer window, I checked my asdf property, and it was still 5.
I also tried it without Form1 open, with the same results. I also tried opening Form1 while the UC's designer window was open, and it opened Form1 but auto-closed the UC's designer window. But asdf still = 5.
Could you provide an example of what you're talking about, maybe with the steps to take to see the problem?
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Feb 8th, 2018, 04:17 PM
#5
Re: To write UserControl's properties at any given time?
Originally Posted by Elroy
Wow, using my example above, I had my Form1 open. Then, I opened the UC (designer) and placed a new label on this UC. While doing that, it hatched-out the UC on Form1, but that's to be expected. But when I close the UC's designer window, I checked my asdf property, and it was still 5.
I also tried it without Form1 open, with the same results. I also tried opening Form1 while the UC's designer window was open, and it opened Form1 but auto-closed the UC's designer window. But asdf still = 5.
Could you provide an example of what you're talking about, maybe with the steps to take to see the problem?
Please folow exactly these steps:
Let's suppose that you already have an UserControl added to form1.
Open form1:
See what value does the property "asdf" have.
If it is 5, then change it to 10, if it is 6, then change it to 10, if it is other, change it to 10.
Remember that value, the last one that you put (it was 10).
Keep the form open, do not close it.
Now open the UserControl designer, and add a label if you want to.
The UserControl in the form must have been hatched-out, as you said.
Now close the UserControl's designer.
The UserControl's instance on the form must be restored non hatched.
But it loses the last value that was entered but not saved.
At least HERE it does not keep the last value entered (10). It shows the last value that was saved the last time I closed the form.
Please pay attention in the steps.
If you confirm that your VB6 IDE is behaving differently, I don't know what to think...
-
Feb 8th, 2018, 07:28 PM
#6
Re: To write UserControl's properties at any given time?
Ahhh, interesting. Eduardo, you are correct. At least now the problem is clear (to me).
I was thinking they got completely reset, but that's not the case. They simply get reset "to the last value from when a WriteProperties was executed", which isn't necessarily the control's default value.
And hence, your question.
So to summarize, property values are lost if you open the UC's designer window after changing a property but before you either close (and maybe re-open) any form using the UC, or save that form to disk; either of which will execute the WriteProperties.
And actually, just opening the code window to the UC, and then doing enough to make it hatch any UC on an open form, does the same thing.
It's an interesting problem. In a sense, you're almost trying to execute code (i.e., the UC's code) while you may be editing that very same code.
You might be able to do something through an add-in, checking to see when a UC's designer window or code window was being opened, and then close any non-UC designer forms that contained the UC. Argh, I'm not a fan of add-ins, so I'll bow out and let you struggle with that one.
At least I'm clear on the problem, and it's a good thing to be aware of.
Good Luck,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Feb 8th, 2018, 07:58 PM
#7
Re: To write UserControl's properties at any given time?
Originally Posted by Elroy
So to summarize, property values are lost if you open the UC's designer window after changing a property but before you either close (and maybe re-open) any form using the UC, or save that form to disk; either of which will execute the WriteProperties.
Exactly, and hence my question about if there is a way to save the data at any given time. When some property is changed, I would like to save the data at that time and not to wait until the form's designer is closed for it to be done.
Perhaps sending some Windows message to force the write.
Originally Posted by Elroy
You might be able to do something through an add-in, checking to see when a UC's designer window or code window was being opened, and then close any non-UC designer forms that contained the UC. Argh, I'm not a fan of add-ins, so I'll bow out and let you struggle with that one.
Forget about that. I've never seen an UserControl that comes with an Add-In.
-
Feb 8th, 2018, 08:12 PM
#8
Re: To write UserControl's properties at any given time?
Originally Posted by Eduardo-
Perhaps sending some Windows message to force the write.
I suspect all of this is deep in the bowels of the VB6 IDE. However, I didn't work it all out, but here's an idea. Maybe you can "grab" a reference to the UC's property bag. That way, you could use this reference to execute a WriteProperty method anytime you wanted. Something like this:
Code:
Option Explicit
Dim pb As PropertyBag
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Set pb = PropBag
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Set pb = PropBag
End Sub
Private Sub Just_To_Illustrate()
pb.WriteProperty "asdf", 123
End Sub
I'm not sure how you're going to "detect" when your UC's designer window (or code window) opens. But, if you can, I believe that'd work to save your properties.
Best Of Luck,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Feb 8th, 2018, 08:20 PM
#9
Re: To write UserControl's properties at any given time?
Good try, but I get error 425:
Code:
Option Explicit
Dim mPB As PropertyBag
Dim mlASDF As Long
Public Property Get asdf() As Long
asdf = mlASDF
End Property
Public Property Let asdf(l As Long)
mlASDF = l
PropertyChanged "asdf"
mPB.WriteProperty "asdf", mlASDF
End Property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
mlASDF = PropBag.ReadProperty("asdf", 0&)
Set mPB = PropBag
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Debug.Print "WriteProperties"
PropBag.WriteProperty "asdf", mlASDF
End Sub
-
Feb 8th, 2018, 08:32 PM
#10
Re: To write UserControl's properties at any given time?
Are you sure that you've already "grabbed" the property bag? Maybe...
Code:
If Not mPB Is Nothing Then mPB.WriteProperty "asdf", mlASDF
EDIT1: That's total air-code though. I'm truly spit-balling at this point.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Feb 8th, 2018, 08:37 PM
#11
Re: To write UserControl's properties at any given time?
Originally Posted by Elroy
Are you sure that you've already "grabbed" the property bag? Maybe...
Code:
If Not mPB Is Nothing Then mPB.WriteProperty "asdf", mlASDF
EDIT1: That's total air-code though. I'm truly spit-balling at this point.
Yes, I'm sure.
-
Feb 8th, 2018, 08:43 PM
#12
Re: To write UserControl's properties at any given time?
No, there is no way.
Thinking about how all this issue works.
PS: is there any way to set a thead "Unresolved forever"?
-
Feb 8th, 2018, 09:26 PM
#13
Re: To write UserControl's properties at any given time?
I can't think of any way around the problem. In IDE design, I think there are 5 events that trigger WriteProperties
1. Clicking the save button for the entire project
2. Unloading the project completely
3. Closing the form from design view
4. Copying a control, i.e., Ctrl+C & Ctrl+V which triggers a write and read event
5. Moving from design to runtime
6. Refreshing the control via right click menu (if control is not hatched)
It's just a thing usercontrol authors are kinda used to: Close all forms before editing a hosted usercontrol. Especially if you are creating a complex control. Is really a pain when you set a dozen properties for testing and forget to cause a save action before going into the code to tweak a line or two, add a comment, etc.
-
Feb 8th, 2018, 10:11 PM
#14
Re: To write UserControl's properties at any given time?
Originally Posted by LaVolpe
I can't think of any way around the problem. In IDE design, I think there are 5 events that trigger WriteProperties
1. Clicking the save button for the entire project
2. Unloading the project completely
3. Closing the form from design view
4. Copying a control, i.e., Ctrl+C & Ctrl+V which triggers a write and read event
5. Moving from design to runtime
6. Refreshing the control via right click menu (if control is not hatched)
It's just a thing usercontrol authors are kinda used to: Close all forms before editing a hosted usercontrol. Especially if you are creating a complex control. Is really a pain when you set a dozen properties for testing and forget to cause a save action before going into the code to tweak a line or two, add a comment, etc.
I'm very used to it LaVolpe, but other people aren't.
I recently posted a control, and the first know user is having a problem regarding this issue.
It is really better to use it in a compiled OCX, but I know that some people want to have everything in the exe.
If they are going to use UserControls in exe projects, they will have to know about this problem and learn how to deal with it.
I was just exploring the possibility of a solution, in case that there was one.
I didn't think there was one, but better to ask, who knows...
-
Feb 8th, 2018, 10:18 PM
#15
Re: To write UserControl's properties at any given time?
Yepper. If people are gonna mess with your code, they are responsible for the consequences. That's always been my personal opinion. In fact, many times I won't even help troubleshoot after someone modifies my code for their purposes. However, if they are helping me troubleshoot a bug in my code -- that's a different story.
In any case, it is a matter of education for the user -- not your concern. Again my opinion only.
-
Feb 8th, 2018, 10:40 PM
#16
Re: To write UserControl's properties at any given time?
Originally Posted by LaVolpe
Yepper. If people are gonna mess with your code, they are responsible for the consequences. That's always been my personal opinion. In fact, many times I won't even help troubleshoot after someone modifies my code for their purposes. However, if they are helping me troubleshoot a bug in my code -- that's a different story.
In any case, it is a matter of education for the user -- not your concern. Again my opinion only.
I don't think there is any bug (related to that issue).
It simply doesn't save what control is on each tab when it gets hatched-out (it happened to me many times).
And the control is subclassed in the IDE what make the things worse.
I'm thinking of putting a note about using it just compiled in an OCX.
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
|