views:

211

answers:

3

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?

A: 

In delphi you can create new code template by File --> New --> Other File --> Code Template

You can go through this site. There are few custom code template examples

http://delphi.wikia.com/wiki/Delphi_Live_Templates

Bharat
Thanks Bharat. I have being playing around with those template on Delphi.Wikia, but I can't hem to create the private field on class completion, only when I create a read/write only property and not when the property use a getter and a setter.
Anders Pedersen
A: 
Sertac Akyuz
Akyuz your are completely right, but the problem is when you make a property with a getter and a setter, the class completion generate the procedure and function needed - But no private field.If you make the property with a getter or a setter and a private field (FNumber) the class completion generates the setter and the private field.
Anders Pedersen
@Anders - Generate the setter and the private field in the first round by only introducing the property, in the second round modify "read FSomething" to "read GetSomething". Well, I can't say for anyone else, but I'm not annoyed at all with the burden of the second round.
Sertac Akyuz
+1  A: 

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.

TOndrej
Thanks TOndrej - Thats nearly the same as I use now, but as you say it don't generate the private field.
Anders Pedersen
Oops. Totally missed the script tag in your example. Sorry!
Ulrich Gerhardt