Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag&Drop Label from container1 to container2 3

Status
Not open for further replies.

gjbbroekhuis

Programmer
Jun 11, 2013
17
0
0
NL
Hi,

I'm trying to create a form with drag & drop. I want to move a label from container1 to container2. Later there will be more containers to choose.
I can move the label, but the drop doesn't place it in container2. See attached form in ZIP-file:
There are so many OLE drag/drop properties in the form, the containers and in the label that I'm confused how to do this.
I tried to follow the Microsoft code from
I'm probably overlooking the obvious, but what?

Regards, Gerrit

Today is only yesterday's tommorrow - Uriah Heep
 
In the KB sample code the OleDragDrop event just sets coordinates of the dragged control.

You would need to change Parent, but you can't in code, at this point the old label would need to be removed and a new label placed inside the other container. You can't change the parent container of a control. So the problem isn't Ole Drag&Drop related, it's a problem of the Object hierarchy of VFP forms. Once a control is create at designtime or via container.AddObject that's where it's the child object, only a new object can be child of another parent, so you'd need to clone the label, in the simplest case addobject the same label class and set caption, height, width, wordwrap and other important properties.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Some years ago I posted in my blog about copying objects from one container to another.
Here is the code from my posting:

Code:
LPARAMETERS vObj as Object
= AMEMBERS( gaPropArray , vObj , 1 )
WITH Thisform.container2 
    * // trying to create a same named object in the target container    
    * // in case there is already a so named object, the CATCH will fire
    TRY 
        .AddObject( vObj.Name , vObj.Class )
        FOR liLoop = 1 TO ALEN( gaPropArray , 1 )
            oNewObj = EVALUATE( [Thisform.container2.] + vObj.Name )
            IF gaPropArray( liLoop , 2 ) = [Property]
                * // Some Props are write protected, so just try to assign a new value
                TRY 
                    oNewObj.&gaPropArray( liLoop , 1 ) = vObj.&gaPropArray( liLoop , 1 )
                CATCH 
                ENDTRY 
            ENDIF         
        ENDFOR 
    CATCH 
        MESSAGEBOX([Object already exists!],0+16+0,[Can't copy object])
    ENDTRY     
ENDWITH

This code is placed as method in a central available object, i.e. _screen.oCopyHandler.DoCopy( This )

In your case, this democode needs another parameter that gives the reference to the targetobject.


-Tom
 
Hi Tom,

I succeeded in recreating the same label with your code in container2.
Now I have to remove the "old" label in container1 in the container2.dragdrop event in order to create a "move" between the two containers.

I tried

Code:
ThisForm.Container1.RemoveObject(oSource)

but this is not working "Function argument value, type, or count is invalid". oSource is the source label in container1, and I'm sure it still exists in container1.

Regards,

Gerrit

Update: ThisForm.Container1.RemoveObject(oSource.Name) works!
 
RemoveObject just needs the name of the object, not an object reference, so use

Code:
ThisForm.Container1.RemoveObject(oSource.Name)

Bye, Olaf.

Olaf Doschke Software Engineering
 
Another idea is to add a RemoveSelf() method to all your controls doing:

Code:
This.Parent.RemoveObject(This.Name)

And then in the DragDrop event do

Code:
oSource.RemoveSelf()

Also add a CloneSelf method, perhaps, with the overall advantage of such OLE helper methods to handle everything individually per control, even in case of more complex controls like a container with label+control or other composite controls.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top