There have been alternatives suggested over time. Parameterized Macro Definitions (ugh, what an ugly name!) offer a new approach to this problem, a new simpler way to implement the solution, and a mechanism for creating an unlimited number of other definitions.
First an example:
Suppose you had a cursor (or table) with an alias of SomeName, and you wanted to insert into your method code the list of all fields in SomeName. With PMDs, you would enter:
Select ##Flds SomeName
So, what is going on?
- ## is the marker for the beginning of the PMD.
- Flds is the PMD keyword (case-insensitive)
- SomeName is the parameter which will be passed along to the sub-routine for processing
Planned PMDs | Description |
---|---|
## Flds FileName | Inserts the list of all fields from FileName, one per line, as would be used by SQL-SELECT. Qualifiers may be added later, to allow for searching for the file (if not open) and to insert an alias before each field name |
## From FileName, ID=OtherFile.ID, etc. | Inserts a FROM statement (for SQL-Select) and related JOIN statements; e.g., From Filename Join OtherFile on Filename.ID = OtherFile.ID |
## LS FileName | Creates a new window to display the structure for Filename |
## ? | Creates a new window to to display a list of all PMDs (much like this list |
Create your own PMDs
The neatest thing about this is that you can create new PMDs very simply, by adding creating new Plug-Ins. The code is very easy to write (the PRG is passed the keyword and parameter, and returns the text to be inserted).
Furthermore, the code for each of the PMDs to be included here will be available in the Sample Plug-Ins folder. You will see there is precious little code, and it's not very sophisticated at all. You may even want to modify it (for instance, if you don't like the way the field names are created for ## Flds.)
All that needs to be done is to create a PRG named HASH<something>.PRG into the the Plug-Ins folder, follow the structure and comments from the samples, and you can create your own PMDs, working on their own keywords.
This is not quite ready for use (unfortunately). Look for release 6.11.003 soon. Possibly this weekend if all goes well.
Many thanks to Tore Bleken on this one. He posted the original suggestion and through a succession of emails we arrived at the the design described above. Thanks, Tore!
Jim, this is awesome. Can't wait for it and i already have a plethora of ideas. Guess that soon i'll replace a big chunk of my "DevTools" menu with PMDs :)
ReplyDeletebtw, will this work for one-line inserts only or multiple lines too (like assigning the controlsource for a form's controls) ?!
There is really no limit to what your own PMD an do. All that has to happen for a PMD to be called is that you have the leading ## prefix, followed by the keyword.
ReplyDeleteThen, when your PMD is called, you have complete control over what happens. It is presumed that the usual case will be to replace the PMD with text, so that is handled by the result returned.
However, you also have access to a class which has a number of methods for manipulating ALL the text in the method window. In fact, ALL of BeautifyX is based on these tools, and could have been implemented this way.
As you will see when I get the release out, returning a multi-line result works just fine.
Cheers