Delegates

P.S. Kem, sorry for the bother - might want to correct post above where you quoted my original (bad) code - I still get a syntax error using

myDelegate = WeakAddressOf( self.myObject.myMethod )

and if I remove the parentheses, the error goes away

myDelegate = WeakAddressOf self.myObject.myMethod

LR might include that? AddressOf and WeakAddressOf apparently don’t use the familiar method syntax where the parens are optional - looks like the the parens can’t be there or we get a syntax error.

Yes, that is an oddity about those particular functions.

( P.S. I’ve tried editing my post above to point out my own mistake, but for some reason the forum isn’t letting me edit the post. )

AddressOf and WeakAddressOf are actually listed as Operators so they have a different syntax. AddressOf is also listed on the Keywords page, as is AddHandler, but WeakAddressOf isn’t there. Not sure what to make of that.

AddressOf is NOT a function. Therefore, you cannot use parentheses. It’s an operator, like + or NOT. Don’t try to use it like a function call.

I get it, but that argument for not using parens doesn’t work, since with operators, we can still use parens if we want to:

x = 1+ aValue
x = (1 + aValue)
if ( thisValue ) or not ( thatValue ) then

etc.

Right? So it still seems to me if there is some reason parens can’t be used, there should be a note about it, because it looks like perfectly valid code to use the parens, both if I’ve mistaken it for a function, and if I understand it’s an operator.

FYI, I just updated the LR for Delegate, AddressOf, and WeakAddressOf.

The grammar says “no parens”
They’re illegal in that case
Thats why

They have their own syntax production rules since they are not like + / - etc which they can be combined in any kind of generalized way in an “expression”
You can’t write (even hypothetically)

dim i as delegate = i + WeakaddressOf( someMethod )