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

Can You Use Variables as Property Names? 2

Status
Not open for further replies.

toddsevans

Technical User
Aug 20, 2004
19
US
I'm curious if it is possible to replace a property such as FontBold with a variable. For example:

THISFORM.lblText1.VarName = .T.

in place of:

THISFORM.lblText1.FontBold = .T.


I'm trying to manipulate the appearance of text on a form without having to create a new variable for each font property.
 
Thanks, but since I am new to this it isn't obvious from your reply what I need to do. So I'll give more detail about how I am approaching this. I have a program that takes a user entered string (a name) and searches a table for that string. If the string is found the following code is executed:

s_messagetitle = "VERIFY CLIENT"
s_messagetext1 = "You chose the borrower"
s_messagetext2 = ALLTRIM(doc1.trust1)
s_messagetext3 = "Is this the borrower you wanted?"
l_font_control_1 = .T.
l_font_control_2 = .T.
l_font_control_3 = .F.
l_showbutton1 = .T.
l_showbutton2 = .F.
l_showbutton3 = .T.
s_buttonname1 = "YES"
s_buttonname3 = "NO"
n_windowmode = 1
n_windowheight = 120
DO FORM displaymessage

So I have all these variables that control what the text of the message is and which buttons are visible etc.

The INIT event of displaymessage looks like this:

l_button1 = .F.
l_button2 = .F.
l_button3 = .F.

* This section determines what buttons will be visible
IF l_showbutton1 = .T.
THISFORM.commandgroup1.VISIBLE = .T.
ELSE
THISFORM.commandgroup1.command1.VISIBLE = .F.
ENDIF

IF l_showbutton2 = .T.
THISFORM.commandgroup1.VISIBLE = .T.
ELSE
THISFORM.commandgroup1.command2.VISIBLE = .F.
ENDIF

IF l_showbutton3 = .T.
THISFORM.commandgroup1.VISIBLE = .T.
ELSE
THISFORM.commandgroup1.command3.VISIBLE = .F.
ENDIF

*This section determines whether or not text lines are bold
THISFORM.lblMessage_Line_1.FontBold = l_font_control_1
THISFORM.lblMessage_Line_2.FontBold = l_font_control_2
THISFORM.lblMessage_Line_3.FontBold = l_font_control_3

* This section determines whether the window is modal or modeless
IF n_windowmode = 0
THISFORM.WINDOWTYPE = 0
ELSE
THISFORM.WINDOWTYPE = 1
ENDIF


So you can see how I am passing variables to the form before it is created.

Perhaps I am totally off base with this approach but it works. If there is a more appropriate way to do this I'd love to know what it is. If not, how can I work in your code?
 
No, you can't substitute a variable for a property, but you can cut down the amount of code:

l_button1 = .F.
l_button2 = .F.
l_button3 = .F.

WITH ThisForm
* This section determines what buttons will be visible
.commandgroup1.VISIBLE = l_showbutton1
.commandgroup1.command1.VISIBLE = !l_showbutton1
.commandgroup1.command2.VISIBLE = !l_showbutton2
.commandgroup1.command3.VISIBLE = !l_showbutton3

*This section determines whether or not text lines are bold
.lblMessage_Line_1.FontBold = l_font_control_1
.lblMessage_Line_2.FontBold = l_font_control_2
.lblMessage_Line_3.FontBold = l_font_control_3

* This section determines whether the window is modal or modeless
.WINDOWTYPE = n_windowmode
ENDWITH


Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
Toddsevans,

No, I don't think you are at all off-base, although I'm not clompletely clear what the problem is.

Are you doing all the above code in the same method of the form? If so, the general approach looks OK. Sure, there are probably some opportunities to save a line of code here or there, but nothing worth getting hung up on.

If the code is working, I'd leave it alone and move on to the next part of the app.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
A couple more reductions based on Craig's posted code:
Code:
Store .F. to l_button1, l_button2, l_button3

WITH ThisForm
  * This section determines what buttons will be visible
  .commandgroup1.VISIBLE = l_showbutton1
  .commandgroup1.setall("Visible", !l_showbutton1)
  *This section determines whether or not text lines are bold
  .lblMessage_Line_1.FontBold = l_font_control_1
  .lblMessage_Line_2.FontBold = l_font_control_2
  .lblMessage_Line_3.FontBold = l_font_control_3
  * This section determines whether the window is modal or modeless
  .WINDOWTYPE = n_windowmode
ENDWITH

boyd.gif

craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Also, it should be noted that you can use Macro substitution in order to acheive the desired results:

Code:
Local lcProp
lcProp = "FontBold"
THISFORM.lblText1.&lcProp = .T.

...so it is possible, though the macro substitution is interpreted at runtime and there is an overhead penalty for this.

boyd.gif

craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Cool!!!

Thanks to everyone who responded. I learned way more than I expected to.

But...

I'm trying to make the INIT event as generic as possible. If I use the code suggested it works great but only for that one particular instance.

I'd rather pass variables to the form and have the INIT event determine what to display based on those variables.

I Really Do Appreciate All Of Your Help!

Any more advice?

Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top