mferre
mferre

Reputation: 192

edit object by a second form vb.net

I need to edit values of a main Object by an edit_settings form.

Now I pass the object to edit By Ref to the second form and I edit it directly. When I apply changes and I close edit_settings form nothing happen and the object still the same without changes.

Here my code:

main form

 Private Sub BtnEditStream1_Click(sender As Object, e As EventArgs) Handles BtnEditStream1.Click
    Dim settingsStream = New StreamForm(myEncoder.streams(0), Me)
    settingsStream.Show()
 End Sub

edit_settings form

Public Sub New(ByRef stream As Encoder.Stream, ByRef settingsForm As SettingsForm)
    InitializeComponent()
    myStream = stream
    mySettingsForm = settingsForm
End Sub

...
doing stuff
...

Private Sub BtnApply_Click(sender As Object, e As EventArgs) Handles BtnApply.Click
    myStream.codec = CbCodec.SelectedItem
    myStream.bitrate = CbBitrate.SelectedItem
    myStream.url = TbURL.Text
    myStream.password = TbPassword.Text
    myStream.port = TbPort.Text
    myStream.mount = TbMountpoint.Text
    myStream.name = TbName.Text
    myStream.title = TbTitle.Text
    myStream.genre = TbGenre.Text
    myStream.description = TbDescription.Text
    myStream.isPublic = CbPublic.Checked
    mySettingsForm.UpdateMenu()

    Me.Close()
End Sub

How can I do it in the best way?

Upvotes: 0

Views: 100

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54457

Rather than being a structure declared within the Encoder class, that Stream type should be a class declared independently. Do that and then get rid of both ByRef keywords here:

Public Sub New(ByRef stream As Encoder.Stream, ByRef settingsForm As SettingsForm)

i.e.

Public Sub New(stream As Stream, settingsForm As SettingsForm)

and everything will work the way it should.

Upvotes: 1

Related Questions