Mega Code Archive

 
Categories / Delphi / Ide Indy
 

Creating Custom Code Templates in Delphi 2006

Title: Creating Custom Code Templates in Delphi 2006 One of the new features in Delphi 2006 are live code templates. Code templates provide a means of automating the task of typing frequently used code structures. Beside providing a set of predefined code templates, Delphi 2006 allows you to add your own custom templates. To see the full list, select "View - Templates" from the main IDE menu. A docked window will appear. Existing templates are stored in an XML file format in the BDS\4.0\objrepos\code_templates folder, a sub-folder exists for each language type. "Open URL in Browser" Custom Template Here's how to create a code template to open an URL in your default browser: To create an empty custom code template click the "New" button on the templates toolbar dialog. Optionally, you can pick File | New | Other | Other Files | Code Template. A skeleton for your custom template will get displayed in the Code Editor. Firstly, set the name (attribute) of the template (tag). Let's call it "url" The "invoke" attribute specifies how this template is invoked. Possible values include: manual - invoked by pressing TAB; auto - invoked by pressing SPACE or TAB; none - invoked by using CTRL+J, CTRL+SPACE, or using the template viewer.Specify "auto". Secondly, fill the "author" and the "description" sections. Next, put in the template code (CDATA section) and specify which language we're targeting ("code" tag with attributes). Declare a "jump point" section so that the template parser knows where to put the url you type while using the template. Finally, save the template in the templates folder, name it "url.xml" Here's the complete "Open URL in Browser" template: Open URL in Browser Zarko Gajic delphi.about.com URL of the page That's it. Open a source file, type "url" and hit TAB. Whoah! Related: Creating a simple template to make a more type safe descendant of TBucketList