Search code examples
delphilive-templates

Live Template for Delphi that generate a Property with getter / setter and create the private field?


Searching here and on the internet have not let me to a example of a Live Template for Delphi that generate a Property with getter / setter and also generate the private field and execute the complication. (SHIFT + CTRL + C)

Is this possible?


Solution

  • The example titled "Read/write property" on the already-mentioned Delphi Live Templates page can be modified to generate getter/setter methods instead of a private field:

    <?xml version="1.0" encoding="utf-8" ?>
    <codetemplate   xmlns="http://schemas.borland.com/Delphi/2005/codetemplates"
                    version="1.0.0">
        <template name="prop" invoke="manual">
            <description>
                read write property for field
            </description>
            <author>
                twm
            </author>
            <point name="ident">
                <text>Name</text>
                <hint>the name for the property</hint>
            </point>
            <point name="type">
                <text>Integer</text>
                <hint>the type for the property</hint>
            </point>
            <script language="Delphi" onenter="false" onleave="true">
                InvokeClassCompletion;
            </script>
            <code language="Delphi" delimiter="|">
            <![CDATA[property |ident|: |type| read Get|ident| write Set|ident|;
    |end|]]>
            </code>
        </template>
    </codetemplate>
    

    This, however, doesn't generate the private field.