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

Pulling Control's name from Form Property

Status
Not open for further replies.

DWhitt

Programmer
Jan 28, 2002
3
US
Is it possible to pull a control's name from a form property and then use the property value in a form method to refer to the control. Say I create a new property on a form called 'oControlA' and set it = .NULL. and in the the form's Init event enter this code:

THISFORM.oControlA = "txtXX_Name"

Then in a form method, do something like this:

THISFORM.oControlA.Value = ALLTRIM(XXDataBaseField)

Have tried something along these lines and received errors and was if this is possible using VFP6. Would like to create some code in several events without having to know control's name right then.


Dave Whitt
Roanoke, Va
 
Here's a little snippet I use to draw pictures of machines on a form facing north, south, east or west, in the forms' Init event:

Code:
PARAMETERS oDrawWhere

IF USED("vlayout")
   SELECT "vlayout"
ELSE
   SELECT 0
   USE vlayout
ENDIF
SELECT vlayout
SCAN
   STORE vlayout.objName TO oCurrobj

   IF vlayout.Direction = 'N' OR vlayout.Direction = 'S'
      oDrawWhere.ADDOBJECT(ALLTRIM(oCurrobj), 'imgtool_ns' )
   ELSE
      oDrawWhere.ADDOBJECT(ALLTRIM(oCurrobj), 'imgtool_ew' )
   ENDIF

   WITH oDrawWhere.&oCurrobj.
      .PICTURE  = vlayout.Direction - 'game.gif'
      .LEFT     = vlayout.l_coln
      .TOP      = vlayout.l_rown
      .VISIBLE  = .T.
      .DRAGMODE = 1
   ENDWITH
ENDSCAN

Parameter 'oDrawWhere' is the name of the form or pageframe where the items are to be drawn.

VLAYOUT.DBF is the table which contains:
ObjName C(30) - the name property of the created object.
L_Rown & L_Coln N(10)- correspond to the row and column of the form.
Direction C(1) - contains 'N', 'S', 'E', 'W'

I also have them set up so they are 'Drag and Drop'able so the user can move them around on the form. The table gets updated with the new position of the objects so the next time the form is instantiated, it will draw the iems in the new positions.

Dave S.
 
Dave (Whitt),
Instead of:
THISFORM.oControlA.Value = ALLTRIM(XXDataBaseField)
Try:
xxx=THISFORM.oControlA
&xxx..Value=ALLTRIM(XXDataBaseField)

Notes:
1) Mixing macros and Form properties gets syntactically complicated (you can't do &ThisForm.oControlA and get what you think you will - see below).
2) When expanding a macro there is an optional "." on the end to specify the end of the macro expansion.
3) This first "." is only required when you want to put another "." following the expanded expression (hence the need for two above).
4) Thank the people at the former Ashton/Tate (dBase) for this arcane syntax.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top