Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Remove Objects from a Form
Message
De
03/09/2005 10:41:01
 
 
À
03/09/2005 07:21:01
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
01046174
Message ID:
01046548
Vues:
20
>>>>Dear All,
>>>>
>>>>I append several objects programmatically, how can I remove it "automatically"?
>>>>e.g.
>>>>
>>>>nEditBox1
>>>>nEditBox2
>>>>nEditBox3... nEditBox999
>>>>
>>>>How can I issue a command to remove them all?
>>>>
>>>>
>>>>FOR x = 1 TO 999
>>>>    nLabel = EVALUATE([nEditBox]+TRANSFORM(x))
>>>>    f_form.removeobject(nLabel)
>>>>ENDFOR
>>>>
>>>>
>>>>However, I don't know how many EditBox I added beforehand...?!
>>>
>>>If they're from same class you can brodacast a message to tell them to remove themselves. ie:
>>>
>>>*Custom property Action
>>>*Action_assign
>>>lparameters vNewVal
>>>if vNewVal='destroy' and type('this.parent')='O'
>>>   this.parent.RemoveObject(this.name)
>>>endif
>>>
>>>thisform.SetAll('Action','destroy','myClass')
>>>
Cetin
>>
>>Hi Cetin,
>>when I have seen this code
>>I thought that VFP collapsed with two or more objects,
>>because when it remove the first one,
>>all the indexes of the collection move back him of one
>>(the collections of VFP are implemented as array,
>>and this is a coarse error,
>>correct implementation it is with a linked list ....)
>>but enough an only object to make to collapse VFP,
>>because when VFP goes out of Broadcast_Assign all the pointers C++ they are corrupt,
>>and when the routine c++ looks for the following one it goes out a violation of memory.
>>
>>
>>PUBLIC oform1
>>
>>oform1=NEWOBJECT("form1")
>>oform1.Show
>>
>>DEFINE CLASS form1 AS form
>>
>>	ADD OBJECT tx2 AS tx WITH ;
>>		Left = 79, ;
>>		Top = 115, ;
>>		Name = "Tx2"
>>
>>	PROCEDURE Click
>>		Thisform.SetAll("BroadCast",.f.)
>>	ENDPROC
>>
>>ENDDEFINE
>>
>>DEFINE CLASS tx AS textbox
>>
>>	broadcast = .F.
>>
>>	HIDDEN PROCEDURE broadcast_assign
>>		LPARAMETERS vNewVal
>>		this.Parent.RemoveObject(this.Name)
>>		WAIT WINDOW "don't touch nothing or me I die"
>>	ENDPROC
>>
>>ENDDEFINE
>>
>
>Maybe just setting visibility would work for Aaron, instead.
>Cetin

I think this:
- reverse removing ( is more efficient and OOP correct )
of a class into Parent.RemoveObject
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show


DEFINE CLASS form1 AS form

	ADD OBJECT tx2 AS tx WITH ;
		Left = 79, ;
		Top = 115, ;
		Name = "Tx2"

	ADD OBJECT tx3 AS tx WITH ;
		Left = 79, ;
		Top = 165
		
	PROCEDURE Click
		Thisform.RemoveObject("Tx",.T.)
	ENDPROC

	PROCEDURE RemoveObject(cObjectName,lNameIsClassName)
		IF m.lNameIsClassName
			NODEFAULT
			PRIVATE iMember
			FOR iMember=m.this.Objects.Count TO 1 STEP -1
				=this.Objects[m.iMember].Class==m.cObjectName AND Form::RemoveObject(this.Objects[m.iMember].Name)
			NEXT
		ENDIF		

ENDDEFINE

DEFINE CLASS tx AS textbox

ENDDEFINE
more complex solution:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show

DEFINE CLASS form1 AS form
	
	allowOutput = .F.
	
	ADD OBJECT cn AS Container
	
	ADD OBJECT tx2 AS Tx WITH ;
		Left = 79, ;
		Top = 115, ;
		Name = "Tx2"

	ADD OBJECT tx3 AS Tx WITH ;
		Left = 79, ;
		Top = 165
	
	PROCEDURE cn.Init
		STORE this.AddObject("pippo","Tx") TO this.pippo.Visible
		
	PROCEDURE Click
		=CREATEObject("memberClassKiller",m.This,"Tx")
	ENDPROC

	PROCEDURE RemoveObject(cObjectName,lNameIsClassName)
		IF m.lNameIsClassName
			NODEFAULT
			PRIVATE iMember
			FOR iMember=m.this.Objects.Count TO 1 STEP -1
				=this.Objects[m.iMember].Class==m.cObjectName AND Form::RemoveObject(this.Objects[m.iMember].Name)
			NEXT
		ENDIF
ENDDEFINE

DEFINE CLASS tx AS textbox

	CollectClass = .F.

	HIDDEN PROCEDURE CollectClass_Assign
		LPARAMETERS cClassName
		IF m.This.Class==m.cClassName
			DIMENSION aCollect[ALEN(aCollect)+1]
			aCollect[ALEN(aCollect)]=m.this
		ENDIF
	ENDPROC

ENDDEFINE

DEFINE CLASS memberClassKiller AS Timer

	PROCEDURE Init(oContainer,cClassName,lTopDown)
		PRIVATE aCollect,iItem
		DIMENSION aCollect[1]
		oContainer.SetAll("CollectClass","Tx")
		IF m.lTopDown
			* TOP DOWN
			FOR iItem=2 TO ALEN(aCollect)
				?  aCollect[m.iItem].Name
				aCollect[m.iItem].Parent.RemoveObject(aCollect[m.iItem].Name)
			NEXT
		ELSE
			* BOTTOM UP
			FOR iItem=ALEN(aCollect) TO 2 STEP -1
				? aCollect[m.iItem].Name
				aCollect[m.iItem].Parent.RemoveObject(aCollect[m.iItem].Name)
			NEXT
		ENDIF
		RETURN .F.
	ENDPROC
	
ENDDEFINE
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform