<< Click to Display Table of Contents >> Navigation: Basic Usage > How to use Macros |
Macro: is a tag to identify the place where the string should be replaced in your text or code. The macro is identified with initial Percent Sign Character (%) whose function is to be used as a marker for text replacement. You can use another chars if you wish so. This is the core feature of this package: With macros you can manipulate values, search strings easily and customize data. Is the same principle you can make with "params" in VCL queries components. By the way, is the same syntax.
And more, you have all the power string handling that Delphi Pascal can provide when working with strings.
For example, where:
"My name is Fred"
We would have the text:
"My name is %NAME"
To be hosted in the STRINGS properties in the components. Therefore, that %NAME would be a identifier to macro replacement .
Looking at the example below (uniGUISimplesciMacroStrInjector) is the simplest example to understand the basic functions.
a- At the left, the original string. The easy way is create you text or import and place the SIGN (default %) and the name of of your choose.
b- At the ObjectInspector see Strings (a string container with editor) and TMacros Property. Every time you modify Strings Property Content, the component will try to read and automatically generates TMacros objects in the Macro Editor. So be aware of this feature. Is the simplest form to see if your macro is recognized by the component BEFORE you run your application..
c- Once pasted the text in the Strings property...
d- and opening the TMacros Editor, he will set all macros recognized.
e-Then you can either define a default value...
f-and type, or just leave as it is. So the result is like that below:
in the example below, at OnClick event we place: ciMacroStrInjector.ExpandMacro;
to execute the macro expansion and associate to the memo content.
h- Another example inputting the value at the fly.
In the example below, we place the code: ciMacroStrInjector.macrobyname('NAME'),value := edName.text;