Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamically creating objects
Message
From
22/05/2005 18:02:31
 
 
To
22/05/2005 15:07:18
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7 SP1
Miscellaneous
Thread ID:
01016598
Message ID:
01016630
Views:
7
This message has been marked as a message which has helped to the initial question of the thread.
>>>I create labels dynamically on my form (in LOAD). Everything works well doing that but now I want to add the code related to the events (Click) within each of the created labels.
>>>
>>>What should I do now?
>>What is the code you are using to create the labels? you should be able to add methods the same way you do properties.
>
>Here's an extract of the code
>
>
>for lnI = 1 to thisform.Something
>   for lnJ = 1 to thisform.SomethingElse
>      lcNom_lbl = "lbl_rv_" + alltrim( str( lnI)) + "_" + alltrim( str( lnJ))
>
>      lcAddObject = "thisform.AddObject( '" + lcNom_lbl + "', 'label')"
>      &lcAddObject
>   endfor
>endfor
>
>
>So for each label I'd like to add the "Procedure Click" that goes with it

Not very complex build dynamic classes into VFP:
PUBLIC mmform
mmform = CREATEOBJECT("myForm")
mmForm.show

DEFINE CLASS myForm as Form
	Something = 2
	SomethingElse = 2
	
	PROCEDURE Load
		
		someClickCode="MESSAGEBOX([this is a fly code])"
		
		defineFlylabel = ""
		 
		TEXT TO defineFlylabel TEXTMERGE NOSHOW
			SET PROCEDURE	TO SYS(16) ADDITIVE
      		DEFINE CLASS mylabel as Label
      			AutoSize = .T.
      			Caption  = "Click here"
      		
      			PROCEDURE Click

		ENDTEXT
 		defineFlylabel = defineFlylabel + someClickCode
	
		TEXT TO defineFlylabel TEXTMERGE NOSHOW ADDITIVE
&&		
			ENDDEFINE
		ENDTEXT
		MESSAGEBOX(defineFlylabel )
		
*		=EXECSCRIPT(defineFlylabel) && CRASH
		
		RANDOMFILENAME=FORCEEXT(FORCEPATH(SYS(2015),SYS(2023)),".TMP")
		
		STRTOFILE(defineFlylabel,RANDOMFILENAME)
		COMPILE (RANDOMFILENAME) NODEBUG
		ERASE (RANDOMFILENAME)
		DO (FORCEEXT(RANDOMFILENAME,"FXP"))
		
		thisform.AddProperty("lbl_rv("+LTRIM(STR(thisform.Something))+","+LTRIM(STR(thisform.SomethingElse))+")",NULL)
		for lnI = 1 to thisform.Something
		   for lnJ = 1 to thisform.SomethingElse
		     thisform.AddObject("lbl_rv(" + ltrim( str( lnI)) + "," + ltrim( str( lnJ))+")" , 'mylabel')
		     WITH this.Controls(thisform.ControlCount)
		     	.Move(5+lnI*100,5+lnJ*30)
		     	.Visible = .T.
		     ENDWITH
		   ENDFOR
		endfor
	
	PROCEDURE UNLOAD
		SET PROCEDURE TO
		
ENDDEFINE
Previous
Reply
Map
View

Click here to load this message in the networking platform