Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Boudewijn Lutgerink
  Where is Boudewijn Lutgerink?
 Hoonaardstraat, Driel
 Netherlands
 Boudewijn Lutgerink
 To: Rene Relucio
  Where is Rene Relucio?
 Quezon City
 Philippines
 Rene Relucio
 Tags
Subject: RE: Creating objects using variables
Thread ID: 99531 Message ID: 99538 # Views: 26 # Ratings: 1
Version: Visual FoxPro 8 Category: General VFP Topics
Date: Friday, June 23, 2006 8:13:47 AM         
   


> hi experts!
>
> I just what to know if below is a good coding practice.
> What it wants to achieve is to create the label and the corresponding textbox into the form from a table.
>
> nTop = thisform.cmdAcceptDate.Top+thisform.cmdacceptdate.Height + 15
> nLeft = thisform.cmdAcceptDate.left
>
> SELECT rv_games
> GO TOP
> FOR I = 1 TO RECCOUNT("rv_games")
> str_I = ALLTRIM(STR(I))
> txtobjname = "txt"+str_I
> lblobjname = "lbl"+str_I
> thisform.AddObject(txtobjname,"TEXTBOX")
> thisform.AddObject(lblobjname,"LABEL")
> WITH thisform
> =ADDPROPERTY(.&lblobjname,"top",nTop)
> =ADDPROPERTY(.&lblobjname,"left",nLeft)
> =ADDPROPERTY(.&lblobjname,"caption",ALLTRIM(gamename))
> =ADDPROPERTY(.&lblobjname,"visible",.t.)
> =ADDPROPERTY(.&lblobjname,"autosize",.t.)
> =ADDPROPERTY(.&txtobjname,"top",nTop)
> =ADDPROPERTY(.&txtobjname,"left",nLeft)
> =ADDPROPERTY(.&txtobjname,"left",120)
> =ADDPROPERTY(.&txtobjname,"visible",.t.)
> =ADDPROPERTY(.&txtobjname,"autosize",.t.)
> txtobjnameheight = txtobjname+".height"
> nTop = nTop + .&txtobjnameheight + 10
> ENDWITH
> SKIP
> ENDFOR
> thisform.height = nTop + 50
>
> Is alright to use the ampersand -> &
> Is there a better way?
> -Thanks.
> Rene-PCSO


you add properties that are already there. Why not simply call these?
I ommited the autosize property for the textbox in the following code, maybe you have a use for it. It did not show in the given codesnippet.
Also, instead of skipping through the records in a for ... endfor looop I suggest using scan ... endscan.
My wild guess is this codesnippet comes form a method on the form itself, I thus changed all the THISFORM statements to THIS (and placed them all in a with ... endwith)

all in all I would rewrite this snippet to:

   WITH THIS

	nTop  = .cmdAcceptDate.TOP + .cmdAcceptDate.HEIGHT + 15
	nLeft = .cmdAcceptDate.LEFT

	SELECT rv_games
	SCAN 
		str_I = TRANSFORM(RECNO())
   
		txtobjname = "txt"+str_I
		lblobjname = "lbl"+str_I
		.ADDOBJECT(txtobjname,"TEXTBOX")
		.ADDOBJECT(lblobjname,"LABEL")

		.&lblobjname..top= nTop
		.&lblobjname..left=nLeft
		.&lblobjname..Caption =ALLTRIM(gamename)
		.&lblobjname..visible = .T.
		.&lblobjname..autosize=.T.

		.&txtobjname..top=nTop
		.&txtobjname..left=nLeft
		.&txtobjname..left=120
		.&txtobjname..visible=.T.
		txtobjnameheight = txtobjname+".height"
		nTop = nTop + .&txtobjnameheight + 10
	ENDSCAN
	.HEIGHT = nTop + 50
ENDWITH



Boudewijn LutgeĀ®ink
My Blog is here


COMPLETE THREAD

Creating objects using variables Posted by Rene Relucio @ 6/23/2006 6:10:28 AM
RE: Creating objects using variables Posted by Boudewijn Lutgerink @ 6/23/2006 8:13:47 AM
RE: Creating objects using variables Posted by Carlos Alloatti @ 6/23/2006 9:06:41 AM
RE: Creating objects using variables Posted by Boudewijn Lutgerink @ 6/23/2006 9:51:43 AM