IDragDrop.ReadParams

Fore Syntax

ReadParams(Source: Variant): IDragDropParams;

Fore.NET Syntax

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

Parameters

Source is an 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 are dragged in the .Net-component.

Comments

On processing events of a .NET component parameters of the traced event are available in the property E. 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 ReadParams method. ObjectToStream.

Example

Executing the example requires a form, the TreeList component named TreeList1 positioned 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);
        //Signing the RichTextBox component for the events
        NetControlBox1.AttachHandler("DragDrop");
        NetControlBox1.AttachHandler("DragOver");
    End Sub TESTFormOnCreate;

    Sub TreeList1OnBeginDrag(Sender: Object; Args: IBeginDragEventArgs);
    Begin
        //Dragging process initialization
        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
            //DragOver event processing
            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");
                //Dragged data type checking
                //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);
            //DragDrop event processing
            Case "DragDrop":
                //Receive event parameters
                //Parameters have the type System.Windows.Forms.DragEventArgs
                Obj1 := Args.E;
                //Receive value of the DragEventArgs.Data property
                //and convert the obtained data to the type
                //IForeNETRuntimeObjectInstance for the 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 receive 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 the 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 the processing of two events: DragOver that occurs when the data are dragged over the component; DragDrop that occurs after data have been dragged in the area of the component. Two handlers for the events of the RichTextBox component are written in the OnEvent event. The process of 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 are checked. When the dragging is completed in the area of the RichTextBox component, the text received from the argument of the event is set as the text of the component.

See also:

IDragDrop