Question

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!

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top