Home All Groups Group Topic Archive Search About

VB Guru please explain me how this can work ?

Author
25 Sep 2006 8:14 PM
aName
How can this work ?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdragactionclasstopic.asp


In Vbasic( see code below)  e is pass ByVal so a copy is put on the stack when the handler is called and it is not suppose to have side effect.

But they clearly do side effect            e.Action = DragAction.Cancel


To do that shouldn't we have at least    ByRef Argument ????

WTF ?




PS
The c++ version is ok 'cause they pass a pointer to e







Private Sub ListDragSource_QueryContinueDrag(ByVal sender As Object, ByVal e As QueryContinueDragEventArgs) Handles ListDragSource.QueryContinueDrag
    ' Cancel the drag if the mouse moves off the form.
    Dim lb as ListBox = CType(sender, System.Windows.Forms.ListBox)

    If Not (lb is nothing) Then

        Dim f as Form = lb.FindForm()

        ' Cancel the drag if the mouse moves off the form. The screenOffset
        ' takes into account any desktop bands that may be at the top or left
        ' side of the screen.
        If (((Control.MousePosition.X - screenOffset.X) < f.DesktopBounds.Left) Or _
            ((Control.MousePosition.X - screenOffset.X) > f.DesktopBounds.Right) Or _
            ((Control.MousePosition.Y - screenOffset.Y) < f.DesktopBounds.Top) Or _
            ((Control.MousePosition.Y - screenOffset.Y) > f.DesktopBounds.Bottom)) Then

            e.Action = DragAction.Cancel
        End If
    End if
End Sub





[C++]
private:
   void ListDragSource_QueryContinueDrag(Object* sender,
      System::Windows::Forms::QueryContinueDragEventArgs* e) {
         // Cancel the drag if the mouse moves off the form.
         ListBox* lb = dynamic_cast<ListBox*>(sender);

         if (lb != 0) {

            Form* f = lb->FindForm();

            // Cancel the drag if the mouse moves off the form. The screenOffset
            // takes into account any desktop bands that may be at the top or left
            // side of the screen.
            if (((Control::MousePosition.X - screenOffset.X) < f->DesktopBounds.Left) ||
               ((Control::MousePosition.X - screenOffset.X) > f->DesktopBounds.Right) ||
               ((Control::MousePosition.Y - screenOffset.Y) < f->DesktopBounds.Top) ||
               ((Control::MousePosition.Y - screenOffset.Y) > f->DesktopBounds.Bottom))
            {

               e->Action = DragAction::Cancel;
            }
         }
      }

Author
25 Sep 2006 8:43 PM
Chris Dunaway
aName wrote:
> How can this work ?

Because the QueryContinueDragEventArgs argument (e) is a reference
type.  When a reference type is passed ByVal, then what is passed is a
*copy* of the reference.  But changing the properties etc of the copy
of the reference changes the original object.

Please see the following article for a more in depth explanation:

http://www.yoda.arachsys.com/csharp/parameters.html


<snip>
Author
25 Sep 2006 8:45 PM
Chris Dunaway
aName wrote:
> How can this work ?

Because the QueryContinueDragEventArgs argument (e) is a reference
type.  When a reference type is passed ByVal, then what is passed is a
*copy* of the reference.  But changing the properties etc of the copy
of the reference changes the original object.

Please see the following article for a more in depth explanation:

http://www.yoda.arachsys.com/csharp/parameters.html


<snip>