IDragDrop.ReadParams

Fore Syntax

ReadParams(Source: Variant): IDragDropParams;

Fore.NET Syntax

ReadParams(Source: Object): Prognoz.Platform.Interop.Forms.IDragDropParams;

Parameters

Source - object that contains data of event argument. The object that contains data in the P4_CONTROL format should be passed as a value of this parameter.

Description

The ReadParams method reads and converts information of the argument of the event that occurs when the data is dragged in the .NET component.

Comments

On handling events of a .NET component parameters of the traced event are available in the E property. These parameters have the System.Windows.DragEventArgs type in the events of dragging. The appropriate .NET methods of this type can be used for converting to the P4_CONTROL format. They should be put in the stream beforehand with the help of the following method after converting to pass the data in the ObjectToStream method.

Example

Executing the example requires a form, the TreeList component named TreeList1 on it and the NetControlBox component named NetControlBox1. The AllowDrag property is set to True for the TreeList1 component.

Class TESTForm: Form
    NetControlBox1: NetControlBox;
    TreeList1: TreeList;
    
    Run: IForeNETRuntime;
    Asm: IForeNETRuntimeAssembly;
    RichObj: IForeNETRuntimeObjectInstance;
    
    Sub TESTFormOnCreate(Sender: Object; Args: IEventArgs);
    Var
        Typ: IForeNETRuntimeType;
    Begin
        Run := ForeNETAssemblyClass.Runtime;
        Asm := Run.SystemAssembly("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
        Typ := Asm.Type("System.Windows.Forms.RichTextBox");
        NetControlBox1.CreateControl(Typ);
        RichObj := NetControlBox1.Control;
        RichObj.InvokeMethod("Set_Text""Source text");
        RichObj.InvokeMethod("Set_AllowDrop"True);
        //Sign the RichTextBox component for the events
        NetControlBox1.AttachHandler("DragDrop");
        NetControlBox1.AttachHandler("DragOver");
    End Sub TESTFormOnCreate;

    Sub TreeList1OnBeginDrag(Sender: Object; Args: IBeginDragEventArgs);
    Begin
        //Initialize dragging
        TreeList1.DoDragDrop(TreeList1.FocusedNode.Text, DragDropEffects.Copy);
    End Sub TreeList1OnBeginDrag;

    Sub NetControlBox1OnEvent(Sender: Object; Args: INetControlBoxEventArgs);
    Var
        Obj1, Obj2, Obj3: IForeNETRuntimeObjectInstance;
        Arg: IForeNETRuntimeMethodArgs;
        Bind: IForeNETRuntimeMethodBinding;
        v: Variant;
        EventParams: IDragDropParams;
    Begin
        Select Case Args.EventName
            //Gandle the DragOver event
            Case "DragOver":
                Obj1 := Args.E;
                v := Obj1.InvokeMethod("Get_Data"New Variant[0]);
                Obj2 := Run.VariantToObject(v) As IForeNETRuntimeObjectInstance;
                Arg := Run.CreateArgs(1);
                Bind := Run.CreateBinding(1);
                Bind.Types.Item(0) := Asm.Type("System.Windows.Forms.DragDropEffects");
                //Check dragged data type
                //If data has the type that differs from P4_CONTROL, receiving of data is prohibited
                If Obj2.InvokeMethod("GetDataPresent""P4_CONTROL"As Boolean Then
                    Arg.Value(0) := DragDropEffects.Copy;
                Else
                    Arg.Value(0) := DragDropEffects.None;
                End If;
                Obj1.Type.Method("Set_Effect", Bind).Invoke(Obj1, Arg);
            //Handle the DragDrop event
            Case "DragDrop":
                //Get event parameters
                //Parameters have the type System.Windows.Forms.DragEventArgs
                Obj1 := Args.E;
                //Get value of the DragEventArgs.Data property
                //and convert the obtained data into the type
                //IForeNETRuntimeObjectInstance for further work.
                //The obtained object has the type System.Windows.Forms.DataObject
                v := Obj1.InvokeMethod("Get_Data"New Variant[0]);
                Obj2 := Run.VariantToObject(v) As IForeNETRuntimeObjectInstance;
                //Execute the IDataObject.GetData method to get data
                //in the format P4_CONTROL
                v := Obj2.InvokeMethod("GetData""P4_CONTROL");
                Obj3 := Run.VariantToObject(v) As IForeNETRuntimeObjectInstance;
                //Place received object in the stream and convert it with the help of
                //ReadParams for using in Fore
                EventParams := DragDrop.ReadParams(Run.ObjectToStream(Obj3));
                //Set received data as text
                //the component RichTextBox
                RichObj.InvokeMethod("set_Text", EventParams.Data);
        End Select;
    End Sub NetControlBox1OnEvent;

End Class TESTForm;

On form creation the .NET component named RichTextBox is loaded to NetControlBox1. The RichTextBox component is signed for handling of two events: DragOver that occurs when the data is dragged over the component; DragDrop that occurs after data has been dragged in the component area. Two handlers for the events of the RichTextBox component are written in the OnEvent event. Dragging is initialized, when the user tries to move a node in the TreeList1 component. The text of focused node is used as the dragged date. When cursor hovers in the area of the RichTextBox component, the dragged data is checked. When dragging is completed in the area of the RichTextBox component, the text received from the argument of the event is set as the component text.

See also:

IDragDrop