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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a hook method 1

Status
Not open for further replies.

markros

Programmer
May 21, 2007
3,150
US
Hello,

I have a mover container class. It has 4 buttons (Move one, Move All, Remove One, Remove All) and also allows drag-drop.

Move/Remove one calls this code
Code:
* Move the highlighted entry in the source listbox to the destination listbox.
This.parent.MoveOne(this.Parent.lstSource, this.Parent.lstDestination)
Remove does the same, but the parameters are switched.

Move All calls
Code:
* Move all entries in the source listbox to the destination listbox.
this.Parent.MoveAll(this.Parent.lstSource, this.Parent.lstDestination)
and Remove All does the same in opposite direction.

Here is code in MoveOne method
Code:
LPARAMETERS toFrom AS LISTBOX, toTo AS LISTBOX
LOCAL lcSelect, lnIndex, lnTotItem, llLockScreen

llLockScreen=THISFORM.LOCKSCREEN
THISFORM.LOCKSCREEN=.T.

lnIndex = m.toFrom.LISTINDEX
FOR lnIndex = toFrom.LISTCOUNT TO 1 STEP -1
	IF toFrom.SELECTED[lnIndex]
		lcSelect = toFrom.LIST[lnIndex,1]
		toTo.ADDITEM(lcSelect)
		toFrom.REMOVEITEM(lnIndex)
	ENDIF
ENDFOR

DO CASE
CASE toTo.LISTCOUNT =  1 AND toTo.SELECTEDID[1] = .F.
	toTo.SELECTEDID[1] = .T.
	IF UPPER(toTo.NAME) = UPPER("lstDestination")
		THIS.RefreshDependents_Destination(toTo.LISTITEM[1])
	ELSE
		THIS.RefreshDependents_Source(toTo.LISTITEM[1])
	ENDIF

CASE toTo.LISTCOUNT =  0
	IF UPPER(toTo.NAME) = UPPER("lstDestination")
		THIS.ClearDependents_Destination()
	ELSE
		THIS.ClearDependents_Source()
	ENDIF
ENDCASE

THIS.REFRESH()

THISFORM.LOCKSCREEN=llLockScreen

This is code form MoveAll method
Code:
LPARAMETERS toFrom, toTo
LOCAL lcSelect, lnIndex, lnTotItem
lnTotItem = toFrom.LISTCOUNT

FOR lnIndex =  1 TO m.lnTotItem
	lcSelect = toFrom.LIST(m.lnIndex,1)
	toTo.ADDITEM(m.lcSelect)
NEXT

toFrom.CLEAR()
THIS.REFRESH()

And I have a similar code in drag-drop.

Now, I need to be able to run some custom code when I add items to the right (destination) and then I remove items from it.

I'm not sure how and there to put a call to this method (or different methods) and what parameters (or properties) would I need.

I'd like to hear some ideas.

Thanks in advance.



 
I'd add calls at the top and bottom of the MoveOne and MoveAll methods, like this:

This.BeforeMoveOne()

* The existing code

This.AfterMoveOne()


and analogously for the MoveAll. Then, add the necessary custom methods and populate them as needed in subclasses or instances.

Tamar
 
Thanks. I used just one extra hook method and I also added LastAction property (to tell me if the items were moved or removed) and the array of moved items.

I'm finishing up with the form's logic now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top