473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Set doesn't run when accessing a property that is an object

Hi

I'm sure this is a simple problem ... for someone!

I have a class which exposes a property which is another object (SmartDate):

Public Property CreateDate() As SmartDate
Get
Return _CreateDate
End Get
Set(ByVal Value As SmartDate) ' this never gets called!
_CreateDate = Value
' raise an event
End Set
End Property

SmartDate is basically a clever Date class - the idea being pinched from
Rocky Lhotkas CSLA!

However, whenever I set the CreateDate it calls the Get and hands me back a
reference to my SmartDate, the properties of the SmartDate are then set and
the Set routine in my object never gets called.

What's the best way round this?

Thanks in advance! Noggin
Nov 21 '05 #1
6 1155
"Noggin The Nog" <Noggin The No*@discussions.microsoft.com> schrieb:
I have a class which exposes a property which is another object
(SmartDate):

Public Property CreateDate() As SmartDate
Get
Return _CreateDate
End Get
Set(ByVal Value As SmartDate) ' this never gets called!
_CreateDate = Value
' raise an event
End Set
End Property

SmartDate is basically a clever Date class - the idea being pinched from
Rocky Lhotkas CSLA!

However, whenever I set the CreateDate it calls the Get and hands me back
a
reference to my SmartDate, the properties of the SmartDate are then set
and
the Set routine in my object never gets called.


There must be a problem elsewhere in your code. Can you post the code you
are using to set the 'CreateDate'?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
The SmartDate object has a Text property:

BusinessObject.CreateDate.Text = Textbox1.Text

The SmartDate then parses the date and attempts to convert it to a date
format, it has other properties like IsDate etc.

When step into the above code it first goes through the CreateDate's Get
function and returns a SmartDate object. The Text property is then set on
this object. Consequently the Set function never runs. It's as though I need
to return a ByVal property rather than a ByRef (which I realise I can't do!)

Thanks!

"Herfried K. Wagner [MVP]" wrote:

There must be a problem elsewhere in your code. Can you post the code you
are using to set the 'CreateDate'?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
The set will only be called if you assign a new SmartDate object to the
CreateDate property. It will not be called when you change the
properties of the CreateDate.

This code will cause the Set to be called:

BusinessObject.CreateDate = New SmartDate(...)

This code will NOT cause the Set to be called:
BusinessObject.CreateDate.Text = Textbox1.Text

HTH

Nov 21 '05 #4
I don't really want to make a new SmartDate each time (in this case it
doesn't, but in others it could involve setting lots of properties on the new
object just to change to one I want to). So I assume the only other way out
of this is to take the SmartDate object out, change what I want, and put it
back:

Dim sdTemp As SmartDate
sdTemp = BusinessObject.CreateDate
sdTemp.Text = Textbox1.Text
BusinessObject.CreateDate = sdTemp

Is that really the most efficient way of doing this? Am I right in saying
what I'm trying to do is have a ByVal property?

Thanks everyone for your help!
"Chris" wrote:
The set will only be called if you assign a new SmartDate object to the
CreateDate property. It will not be called when you change the
properties of the CreateDate.

This code will cause the Set to be called:

BusinessObject.CreateDate = New SmartDate(...)

This code will NOT cause the Set to be called:
BusinessObject.CreateDate.Text = Textbox1.Text

HTH

Nov 21 '05 #5
"Noggin The Nog" <Noggin The No*@discussions.microsoft.com> schrieb:
The SmartDate object has a Text property:

BusinessObject.CreateDate.Text = Textbox1.Text


In this code you are not chaning the property' value, which would mean that
you assign a new value to 'CreateDate'. Instead, you are setting a property
/on/ the 'CreateDate''s value. To do that, the value of the 'CreateDate'
property is determined (and thus the 'Get' part of the 'CreateDate' property
is called) and then the property of the 'CreateDate' object is changed.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6
I was merely trying to point out that in the scenario you described,
the Set portion of your property was *not supposed* to run.

As Herfried pointed out, the only time the Set portion runs is when you
assign a *new* SmartDate to the property. Since you're not doing that
here, the Set will not run.

If all you're trying to do is change a property of the
BusinessObject.CreateDate property, then what you originally had is
appropriate.

In other words the following code should be correct:
BusinessObject.CreateDate.Text = Textbox1.Text

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: vadivasbro | last post by:
Very simple code. Why won't this work? <html> <head> <script type="text/javascript"> window.onload = document.getElementById("thisThing").style.background = "red"; </script>
60
by: Dave | last post by:
I'm never quite sure whether to use "this." or not when referring to fields or properties in the same class. It obviously works just fine without it but sometimes I wonder if using this....
21
by: alistair_henderson | last post by:
Morning All, I have some code for a website which uses 'window.open' to simulate modal dialog boxes. I use the window.closed property to decide if the window object exists at various points. ...
28
by: ensemble | last post by:
I'm trying to utilized a more object-oriented approach to managing window events in javascript. Thus, I am creating a "controller" object to handle events and interact with the server. However, I...
8
by: RSH | last post by:
Hi, I have a situation where I have a Parent Object (Company) which has several public properties. The Company Object also creates an Employees object which has its ow set of functions and...
8
by: Radu | last post by:
Hi. I have an ASP control on my page: <asp:Calendar ID="calStart" ................ Etc </asp:Calendar> and I have a Custom Validator defined as <asp:CustomValidator
1
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
38
by: tshad | last post by:
In VS 2008, why doesn't ToString require "()". If I have Option Strict On on why can I do both: selectedIndex.ToString() selectedIndex.ToString or sQuery =...
14
by: Rafe | last post by:
Hi, I've encountered a problem which is making debugging less obvious than it should be. The @property decorator doesn't always raise exceptions. It seems like it is bound to the class but...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.