Archive | Castalia for Delphi RSS feed for this section

Castalia Code Templates – A Primer

Castalia’s code template system for the Delphi IDE is actually a scripting system. Borrowing from web programming systems like PHP or ASP, Castalia’s templates are a combination of text to be inserted directly into the editor and of scripting code, contained between {% and %} markers.

The scripting language is Delphi-based, so there’s no syntax to learn as you write really powerful code templates. Here’s an example of what the ifb template looks like (ifb inserts an if statement with a begin..end block):

    if {% InsertCursor(0) %} then
    begin
    {%= Indent %}{% InsertCursor (1) %}
    end;

Everything not between {% %} markers is inserted directly into the Delphi code editor. Code between the {% %} markers is executed. This example shows the InsertCursor(AOrder: Integer) procedure, which drops a stack bookmark at that point in the text. The bookmark with AOrder = 0 will be the location of the cursor after the template is done executing. The bookmarks are then picked up in the order indicated by the AOrder parameter.

Also notice the {%= marker, which means “insert the result of this code into the editor.” Indent returns a string of spaces matching your indent size.

Here’s an example of a template to insert the current method name as a string:

    {% if ClassName <> ” then
    begin
    %}{%= ClassName %}.{% end %}{%= ProcedureName %}

Notice the Delphi code right in the template to check whether there is a current class and insert the “ClassName.” before the method name.

Castalia comes with quite a few built-in templates, but the real power is in writing your own.

Castalia Delphi code template editor

Want to give it a try? Download Castalia today and see what you can do with Castalia’s powerful code templates for the Delphi IDE.

Read full story · Comments { 1 }

Welcome

Welcome to the new Castalia blog. Previously, my blog at www.jacobthurman.com was a big unfocused collection of not-necessarily-related things.

Now, instead having to comb through that blog in order to find information on Castalia, you can find it all here.

Don’t forget to sign up for my free newsletter and get exclusive content for free, plus a chance to win a programming book every month.

Read full story · Comments { 0 }

For programmers, by a programmer

Hi. My name is Jacob, and I'm the creator of Castalia.

I starting programming in 1986, learning Lightspeed Pascal on a Mac Classic. Today, I'm a professional programmer, teacher, and entrepreneur.

I have a Master's Degree in Computer Science, and I still love Pascal and Delphi.

I believe that writing code is the heart and soul of software development, and I love helping programmers write code more effectively.