kpgraci
Active member
I have a form that accepts a byval client object in the New
I call this from another form like this:
clsClient implements INotifyPropertyChanged
On the calling form I have labels bound to the properties of the _client object, like first and last name.
On frmEditClient if have textboxes bound to the same fields
What is happening that I don't understand is that when I'm showing the frmEditClient as a modal window of the calling form, when I change
the first name, for example, the labels bound to those fields on the calling form are also changed as I type, indicating that they both point to the same object.
Now this is rather cool, but I expected the object to copied and a new instance to exist in the frmClient modal form, but obviously it is the same instance.
Is this because the object is a reference type and so by specifying byval in the frmEditClient creator has the same effect as passing byref?
I wanted a separate object in case the user edited the object in frmEditClient and then decided to hit the cancel button and not commit the changes. In this case, do I need to clone the client object before I send it to the frmEditClient?
Like this:
Problem: There is no clone method. How do I get a copy of an object that is a new object?
Or is there a better way to do what I'm trying to do?
thx
VB.NET:
private _client as clsClient = Nothing
Public Sub New(ByVal client As clsClient)
InitializeComponent()
_client = client
End Sub
I call this from another form like this:
VB.NET:
Dim f As New frmEditClient(_client)
If f.ShowDialog() = DialogResult.OK Then
_client = f.Client
End If
clsClient implements INotifyPropertyChanged
On the calling form I have labels bound to the properties of the _client object, like first and last name.
On frmEditClient if have textboxes bound to the same fields
What is happening that I don't understand is that when I'm showing the frmEditClient as a modal window of the calling form, when I change
the first name, for example, the labels bound to those fields on the calling form are also changed as I type, indicating that they both point to the same object.
Now this is rather cool, but I expected the object to copied and a new instance to exist in the frmClient modal form, but obviously it is the same instance.
Is this because the object is a reference type and so by specifying byval in the frmEditClient creator has the same effect as passing byref?
I wanted a separate object in case the user edited the object in frmEditClient and then decided to hit the cancel button and not commit the changes. In this case, do I need to clone the client object before I send it to the frmEditClient?
Like this:
VB.NET:
dim _cloneOfClient as clsClient = _client.Clone
Dim f As New frmEditClient(_cloneOfClient)
If f.ShowDialog() - DialogResult.OK Then
_client = f.Client
End If
Problem: There is no clone method. How do I get a copy of an object that is a new object?
Or is there a better way to do what I'm trying to do?
thx