Search code examples
delphidelphi-ide

User defined macro in CnPack


Do you know how to create an user defined macro in CnPack ?

The instructions shipped with it say it can be done but don't explain how. I tried to sign in the dedicated forum, twice, but it didn't work.

I searched for some tutorials online but didn't find anything either.


Solution

  • You simply define the new macro. Here's an example of doing so.

    • Open the Source Templates Options dialog (CnPack->Source Templates->Options from the IDE main menu).
    • Select the Add button.
    • Fill in the information at the top (Title and Description for now), for instance "TestTemplate" and "Test template with my macro". The hard part is finding an unused ShortCut, so let's not bother now.
    • In the content area, put in the text you want to insert into your source. Let's try a third type of comment block with some silly information and a macro named MyMacro - note that I've surrounded it with % characters:

      (*
         This is a nonsense comment by %MyMacro%
      *)
      
    • Save the template, and then close the dialog.

    • Go into the IDE's Code Editor at the point you want to insert the template. Open the CnPack->Source Template menu, where you'll see your new TestTemplate at the bottom. Click it, and you'll see a dialog appear:

    TestTemplate macro replace dialog

    • Fill in the Value (I'll use "Some Value") and click Ok. You should see this in the Code Editor:

      (*
        This is a nonsense comment by Some Value
      *)