ciMacroStrInjector

<< Click to Display Table of Contents >>

Navigation:  Components >

ciMacroStrInjector

It is a component to do simple manipulation of macros in any file that works with standard text format supported by Delphi.

 

The ciMacroStrInjector component can permanently store text in your program resource as well as encrypt the text in the resource file and thus prevent someone from reverse engineering your program and "stealing" the stored data. You could use such component to a lot of function and encryption is good feature already built in  available.

 

How to use it: Insert a text in the Strings property and in the body of this text define the tags that will be used as markers for the macro-replacement. By default, you must use the % (Percent Sign) symbol but you can configure for any other the environment dependent you want to use the component or code that your program should support.

 

Once you've entered the text in the Object Inspector's default editor, check the Macros property. The component will try to check the body text and directly load the macro tags it can find in its string.

 

However, there may be errors or combinations of the tag with the body of the text that the macro manager will not recognize. You can correct the macro's tag name in this step. See the picture below:

 

Clip6

fig 1- ciMacroStrInjector in Object Inspector

 

Properties:
Capacity: For backwards compatibilities.  Probably will be removed in a near future since makes no sense keep it compatible with Delphi version prior to 2010.

KeyString: When provided, the Strings field content is encripted in the DFM file.

MacroChar: Indicates the macro tag in the string content. You can use any other but be aware when to use and the environment language and code.

Strings: The content text to be manipulated. This content is persistent and won't change except with you manipulate the strings as a regular TStrings object.

Macros: Collection of macros in your Strings persistent repository. The component will try to detect macros every time you close the Strings Editor. Be aware that this is not always a desired process but a good start to speed up the process of editing macros for large text. Double-click at this properties will open the collection editor where you might define or correct macro's name, value and type. The type here is to facilitate the final conversion to  your application since all is treated a strings. See picture below:

 

Clip8

fig 2 - Macro editor

 

Clip9

fig 3 - Define macro name at design time

 

Clip10

fig 4 - Another field defined.

 

At these examples shown above, were defined two macro names. Hence, when expanding, the component will search for %NAME and %PHONE tags in the Strings content of the component and make the substitution. Be aware that in this example the default values where defined. It is not mandatory. This can also be defined at runtime.

 

 

Main Methods/Procedures:

ExpandMacros:  Performs the macro expansion in the text contained in Strings field/property returning the converted text. Same as shown in How to use Macros topic's.

 

Events:

OnChange: Trigger at Strings content change, but after the change occurs.

OnChanging: Trigger at Strings content change. At any change detect.

OnExpandMacros: After an ExpandMacros is realized.

 

Manipulating macro values

You can define or change the macro values in two ways: At design time or run-time. as shown in the pictures in this manual or at runtime.

At runtime, the easy method is acessing the macro by its name as the code below:
 
ciMacroStrInjector.macrobyname('NAME'). value := 'Michelle';

 

Using the line above give a new value to the macro container in the component. A regular code would look like the picture below:

 

Clip11

 

fig 5 - A simple code to define and show the resulting expanded text.