Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Evaluate
Message
From
29/06/2003 11:14:33
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
29/06/2003 10:33:36
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00805082
Message ID:
00805100
Views:
32
>Something not clear to me.
>1. 'Eval'='Evluate'?

Most VFP commands can be abbreviated to 4 or more letters. The fact that you can do something doesn't necessarily mean that you should. DISP STRU instead of DISPLAY STRUCTURE in the command window might be acceptable. But in a program that is to be read later by other people (or by you), making an exaggerated use of abbreviations can make the program hard to read. Therefore, I usually write the complete commands. Anyway, I do abbreviate some commands; specifically, I frequently abbreviate evaluate() as eval(), and transform() as trans().

>2. The example working but the principle not enough clear for me.

The basic idea in my example is: use eval() to manipulate several objects in a loop.

Let's start with a simpler example - simpler in the sense that no objects are involved.
x = "y"
y = 3
"x" contains the name of another variable. Now, I want to show the content of this other variable (not its name), using only variable "x".
? x  && Shows the name of the variable, "y". This is not what I wanted.
? eval(x) && Shows the contents of "y".
Returning to my previous example:
for i = 1 to 3
  loTextBox = evaluate("ThisForm.Text" + trans(i))
  loTextBox.FontBold = .T.
next
When i = 1, the text within the evaluate() function is equal to "ThisForm.Text1". Evaluate() will evaluate this expression - in this case, it will return an object reference. Now, I can use loTextBox just as I would use ThisForm.Text1.

If I didn't need to process several objects in a loop, I could just have used:
loTextBox = ThisForm.Text1
loTextBox.FontBold = .T.
The use of an object variable in this case saves you the trouble of writing a longer expression.

In case object variables aren't completely clear to you, compare the following example: A form contains a PageFrame, the PageFrame contains three pages, page1 contains a grid, the grid contains several columns, and each colum contains a TextBox. (Note that this is "real-life: I actually use this complicated containership on real forms.) To make the TextBox in Column1 Bold, Italic, and change the Font to "Courier New", I could use the following commands:
ThisForm.PgfPageFrame.Page1.GrdGrid.Column1.Text1.FontBold = .T.
ThisForm.PgfPageFrame.Page1.GrdGrid.Column1.Text1.FontItalic = .T.
ThisForm.PgfPageFrame.Page1.GrdGrid.Column1.Text1.FontName = "Courier New"
To avoid writing the long expression several times, I can also use an object variable (this is also supposed to work faster):
loText = ThisForm.PgfPageFrame.Page1.GrdGrid.Column1.Text1
loText.FontBold = .T.
loText.FontItalic = .T.
loText.FontName = "Courier New"
(For another way to do this, see also: WITH)

HTH,

Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform