cjard
Well-known member
- Joined
- Apr 25, 2006
- Messages
- 7,081
- Programming Experience
- 10+
I'm writing a parser. When the parser has read a line but not added it to the internal store, it fires a LineAdding event. After it has done this, it fires a LineAdded
I want to enable intercepting of the line, upon Adding, change it, and have the changes stored in the store. Just like a KeyPressEventArgs can be Handled (cancel bubble) or have the char key value modified.. I'm wondering how MS implemented this and hence adopt their approach as a best practice.
Ought I:
Make a class that derives from eventargs
Supply a boolean or make it so that the LineDetail can be set to null
Have my add code do:
Dim lineToAdd as LineDetail = OnLineAdding(lineNow)
store.Add(lineToAdd)
Have my OnLineAdding do (adapted from c#, pseudocode):
Dim lea as new LineEventArgs(theLine)
RaiseEvent LineAdding(lea)
If lea.Cancel Then Return Nothing
Return lea.TheLine
Or do they use ref variables?
Another thought:
Its not valid to allow for changes on the Added event.. so do microsoft just ignore all the changes that are made or do they provide a different object that is readonly for their -ed events, and mutable objects for their -ing ones
That said.. it's all ref values at the end of the da.. the store is a list.. if I change the data from the added line, I can still screw it up.. there's nothing there to sever the link; the line that is notified in the event args, is the same line as exists in the List(of Line), the list points to it, the event args points to it.. mutations to the line will still be reflected in the list..
I want to enable intercepting of the line, upon Adding, change it, and have the changes stored in the store. Just like a KeyPressEventArgs can be Handled (cancel bubble) or have the char key value modified.. I'm wondering how MS implemented this and hence adopt their approach as a best practice.
Ought I:
Make a class that derives from eventargs
Supply a boolean or make it so that the LineDetail can be set to null
Have my add code do:
Dim lineToAdd as LineDetail = OnLineAdding(lineNow)
store.Add(lineToAdd)
Have my OnLineAdding do (adapted from c#, pseudocode):
Dim lea as new LineEventArgs(theLine)
RaiseEvent LineAdding(lea)
If lea.Cancel Then Return Nothing
Return lea.TheLine
Or do they use ref variables?
Another thought:
Its not valid to allow for changes on the Added event.. so do microsoft just ignore all the changes that are made or do they provide a different object that is readonly for their -ed events, and mutable objects for their -ing ones
That said.. it's all ref values at the end of the da.. the store is a list.. if I change the data from the added line, I can still screw it up.. there's nothing there to sever the link; the line that is notified in the event args, is the same line as exists in the List(of Line), the list points to it, the event args points to it.. mutations to the line will still be reflected in the list..