Saturday, March 18, 2006

FoxPro Tips: VFP's EditorOptions

If you author any kind of whitepaper or article with Visual FoxPro example code you quickly understand the need to suppress the rich text formatting included in VFP 9 when you copy code to the clipboard. At first I really liked this feature for my own technical documentation, but when I work with conference session templates, magazine templates, and Hentzenwerke Publishing templates I am frustrated because it breaks the style guides from the various publishers. During the VFP 9 beta the feature was part of the product and not configurable, but the voices of the beta testers were heard loud and clear. We want a way to shut this off.

I have helped many developers turn off this feature, and today while working on my error handling session for GLGDW 2006 I realized I turned this on (nice when sharing code in email or posting on a forum) and need it off while writing the whitepaper. I have a program to toggle the setting. Here is the code:

* Toggle rich text formatting to clipboard
IF 'X' $ _vfp.EditorOptions
* Turn it off
_vfp.EditorOptions = STRTRAN(_vfp.EditorOptions,"X", SPACE(0))
ELSE
* Turn it on
_vfp.EditorOptions = _vfp.EditorOptions + 'X'
ENDIF

You can hook this up to a developer menu item, or toolbar, or just run it from the Command Window.

Bonus Tip
While reviewing the code I remembered another tip to share. IntelliSense has a feature called C++ Operator Expansion. I use this all the time. If you have a variable like lcErrorString and you want to concatenate some text to the existing string you can enter the following in the program editor:

lcErrorString+=

Then hit the space bar and you will see:

lcErrorString = lcErrorString +

You are ready to type in the rest of the logic to perform the concatenation. There are several C++ operators to work with in VFP's IntelliSense.

lnCounter++
lnCounter--
lnCounter+=
lnCounter-=
lnCounter*=
lnCounter/=

The reason I was inspired to write the bonus tip is the situation where you have a object.Property and want to concatenate or increment, like _vfp.EditorOptions. If you have code like this in the program editor:

_vfp.EditorOptions+=

And hit the space bar, nothing happens. I reported this as a bug during one of the betas. The workaround is simple, but you have to remember it when writing code. Include a space between the property name and the operator, then hit the space bar after the operator.

_vfp.EditorOptions +=

Enjoy the weekend!

3 Comments:

At 3/19/2006 08:33:00 AM, Anonymous Andy Kramek said...

Hi Rick
Your note about the necessity of including a space before the "+=" operator is not strictly accurate. It seems to work just fine is mosdt cases - but for the VFP application object it DOES require the space. Try the following in an editing window, or even by instantiating the object in command window:

LOCAL loX as CUSTOM
loX.Height+=

 
At 3/19/2006 10:57:00 AM, Blogger Rick Schummer said...

Andy,

Thanks for the clarification. You are absolutely correct. I guess the reason I have taken the "space approach" every time is it works for the VFP application object and the other objects. One approach is simpler for me to remember.

 
At 3/27/2006 05:04:00 PM, Anonymous Tamar E. Granor said...

I chose the opposite approach with the formatted code. Since I do virtually all my writing with Word, I set up a shortcut in Word to paste without formatting (Edit | Paste Special | Plain Text, or something like that).

 

Post a Comment

<< Home