From: Miro on 28 Apr 2010 12:08 Hi, (vb.net vs2008) I understand the significance between memory pointers with a function using byVal and byRef. However I have code that I want to do something like this: Dim UsMailmsg As MailMessage = EmailOrderClass.createEmailOrder(False, cartOrderID) For nI As Integer = 0 To SendToEmailAddresses.Count - 1 EmailOrderClass.sendEmailOrder(CustomerAddress, ToEmailAddress, UsMailmsg) <------- this line Now When I am using the UsMailmsg, even though the function is specified as "byVal" it will always pass in as a reference to a memory pointer. How do I pass it in as a 'Direct Copy' of the variable. So basically I can create an 'orig' version of the UsMailmsg, then it passes a copy of it into a function where that function changes parameters left and right. But on the next "for next loop" it will send in the orig for the next run of something else. Hope that makes sense. Thanks, Miro
From: Cor Ligthert[MVP] on 28 Apr 2010 12:28 You have to serialize it first. "Miro" <miro(a)beero.com> wrote in message news:ual7L0u5KHA.3292(a)TK2MSFTNGP06.phx.gbl... > Hi, > > (vb.net vs2008) > > I understand the significance between memory pointers with a function > using byVal and byRef. > > However I have code that I want to do something like this: > > Dim UsMailmsg As MailMessage = EmailOrderClass.createEmailOrder(False, > cartOrderID) > For nI As Integer = 0 To SendToEmailAddresses.Count - 1 > EmailOrderClass.sendEmailOrder(CustomerAddress, > ToEmailAddress, UsMailmsg) <------- this line > > Now When I am using the UsMailmsg, even though the function is specified > as "byVal" it will always pass in as a reference to a memory pointer. > How do I pass it in as a 'Direct Copy' of the variable. > > So basically I can create an 'orig' version of the UsMailmsg, then it > passes a copy of it into a function where that function changes parameters > left and right. > But on the next "for next loop" it will send in the orig for the next run > of something else. > > Hope that makes sense. > > Thanks, > > Miro > > > >
From: Tom Shelton on 28 Apr 2010 12:33 On 2010-04-28, Miro <miro(a)beero.com> wrote: > Hi, > > (vb.net vs2008) > > I understand the significance between memory pointers with a function using > byVal and byRef. > > However I have code that I want to do something like this: > > Dim UsMailmsg As MailMessage = EmailOrderClass.createEmailOrder(False, > cartOrderID) > For nI As Integer = 0 To SendToEmailAddresses.Count - 1 > EmailOrderClass.sendEmailOrder(CustomerAddress, > ToEmailAddress, UsMailmsg) <------- this line > > Now When I am using the UsMailmsg, even though the function is specified as > "byVal" it will always pass in as a reference to a memory pointer. > How do I pass it in as a 'Direct Copy' of the variable. > The common way would to implement the IClonable.Clone method - which would return a deep copy of the object. -- Tom Shelton
From: Tom Shelton on 28 Apr 2010 12:39 On 2010-04-28, Tom Shelton <tom_shelton(a)comcastXXXXXXX.net> wrote: > On 2010-04-28, Miro <miro(a)beero.com> wrote: >> Hi, >> >> (vb.net vs2008) >> >> I understand the significance between memory pointers with a function using >> byVal and byRef. >> >> However I have code that I want to do something like this: >> >> Dim UsMailmsg As MailMessage = EmailOrderClass.createEmailOrder(False, >> cartOrderID) >> For nI As Integer = 0 To SendToEmailAddresses.Count - 1 >> EmailOrderClass.sendEmailOrder(CustomerAddress, >> ToEmailAddress, UsMailmsg) <------- this line >> >> Now When I am using the UsMailmsg, even though the function is specified as >> "byVal" it will always pass in as a reference to a memory pointer. >> How do I pass it in as a 'Direct Copy' of the variable. >> > > The common way would to implement the IClonable.Clone method - which would > return a deep copy of the object. > Building upon this - you should realy take a combination of mine and Cor's replies :) A common way to make a deep copy of an object is to serialize it to a memorystream and then desearialize from the memorystream.... -- Tom Shelton
From: AMercer on 28 Apr 2010 13:12
As I understand your question, you need to create a new object, pass it to sendEmail Order(), and then discard it. Perhaps new object could be created by calling createEmailOrder(), or perhaps by UsMailmsg.MemberwiseClone(), or perhaps you need to write a custom cloner. Regardless, if sendEmailOrder changes object properties and you want to ignore them, then you need a fresh (new or cloned) object at each iteration. AMercer "Miro" wrote: > Hi, > > (vb.net vs2008) > > I understand the significance between memory pointers with a function using > byVal and byRef. > > However I have code that I want to do something like this: > > Dim UsMailmsg As MailMessage = EmailOrderClass.createEmailOrder(False, > cartOrderID) > For nI As Integer = 0 To SendToEmailAddresses.Count - 1 > EmailOrderClass.sendEmailOrder(CustomerAddress, > ToEmailAddress, UsMailmsg) <------- this line > > Now When I am using the UsMailmsg, even though the function is specified as > "byVal" it will always pass in as a reference to a memory pointer. > How do I pass it in as a 'Direct Copy' of the variable. > > So basically I can create an 'orig' version of the UsMailmsg, then it passes > a copy of it into a function where that function changes parameters left and > right. > But on the next "for next loop" it will send in the orig for the next run of > something else. > > Hope that makes sense. > > Thanks, > > Miro > > > > . > |