Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i make a "Surround" type Delphi Template?

i'm migrating my app to delphi 2009. my app must still use a lot of AnsiString. during migration, i find myself always converting:

abc := def;

into:

abc := string(def);

or

abc := TDeviceAnsiString(def);

i know i should be able to do this with templates but i find templates--although powerful--are not so easy to get working. here's what i've been trying:

<?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 doesn't appear in the Surround menu and it doesn't activate whenever i want. i'd like to be able to

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

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

abc := TDeviceAnsiString(def);

thank you for your help!

like image 679
X-Ray Avatar asked Oct 29 '08 18:10

X-Ray


1 Answers

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>

Added: You can find more info on the Delphi Wiki with the LiveTemplates Technical Infos

like image 129
Francesca Avatar answered Oct 23 '22 09:10

Francesca