How can I create a "Surround" template like Delphi?

I am porting my application to delphi 2009. My application should still use a lot of AnsiString. during migration, I always convert:

abc := def;

in

abc := string(def);

or

abc := TDeviceAnsiString(def);

I know that I should be able to do this with templates, but I find the templates - albeit powerful ones - not so easy to work with. here is what i tried:

<?xml version="1.0" encoding="utf-8" ?>

<codetemplate   xmlns="http://schemas.borland.com/Delphi/2005/codetemplates"
                version="1.0.0">
    <template name="das" invoke="auto">
        <point name="expr">
            <script language="Delphi">
                InvokeCodeCompletion;
            </script>
            <hint>
                MP: TDeviceAnsiString
            </hint>
            <text>
                True
            </text>
        </point>
        <description>
            MP: TDeviceAnsiString
        </description>
        <author>
            Mike
        </author>
        <code language="Delphi" context="any" delimiter="|"><![CDATA[TDeviceAnsiString(|selected|)|end|]]>
        </code>
    </template>
</codetemplate>

it does not appear in the Surround menu, and it does not activate when I want. I would like to be able

abc := **das***[tab]*def;

or select "def" and use "surround" to get:

abc := TDeviceAnsiString(def);

Thank you for your help!

+5
source share
1 answer

This should do it:

<?xml version="1.0" encoding="utf-8" ?>
<codetemplate   xmlns="http://schemas.borland.com/Delphi/2005/codetemplates"
                version="1.0.0">
    <template name="das" surround="true" invoke="auto">
        <description>
            MP: TDeviceAnsiString
        </description>
        <author>
            Mike rev François
        </author>
        <code language="Delphi" delimiter="|"><![CDATA[TDeviceAnsiString(|end||selected|)]]>
        </code>
    </template>
</codetemplate>

: Delphi Wiki LiveTemplates

+11

All Articles