I have a simple question about passing objects as method parameters.
If I pass an open BinaryStream to a method and read from it, will the position in the stream be altered by the method to whom it was passed to or not? I.e. is it passed ByRef or ByVal by default?
[quote=142260:@Garry Pettet]I have a simple question about passing objects as method parameters.
If I pass an open BinaryStream to a method and read from it, will the position in the stream be altered by the method to whom it was passed to or not? I.e. is it passed ByRef or ByVal by default?[/quote]
Proof is in the pudding. Experimentation :
Sub Action()
dim s as string
Dim readFile As FolderItem = SpecialFolder.desktop.child("index.html") 'GetOpenFolderItem("text")
If readFile <> Nil And readFile.Exists Then
Dim ReadStream As BinaryStream = BinaryStream.Open(readFile, False)
ReadStream.LittleEndian = True
s = ReadStream.Read(56,encodings.MacRoman)
lon(ReadStream)
MsgBox str(ReadStream.Position)
readStream.Close
End If
End Sub
Protected Sub lon(b as BinaryStream)
MsgBox str(b.Position)
dim s as string = b.Read(56,encodings.MacRoman)
End Sub
It is apparently a byref : first MsgBox displays 56, the second one after going through the method displays 112.
Thanks. Much appreciated.
This and this may be useful references in this case.
It is passed ByRef, just like any other object. The ByVal keyword has no effect on them.
The only ones that are not always passed by reference are the simple types like Integer, String, Double, Boolean, Color, Single, etc.