Editor's Note: This article was originally published in June 2004. It has been edited for publication here.

The Hidden Talents of Multipaste

Multi paste is one of my favourite features of Castalia, actually it was my idea in the first place. Not that I mean to gloat or anything, but it that is part of the story.

Working in the office of the airline I worked for (a franchise of British Airways) I found myself writing SQL queries yet again for yet another report someone had just thought up and decided was a necessity. My typical routine for developing a new report is

1) Work out the SQL in IBConsole

2) Paste the SQL into the code editor of Delphi

3) Wrap it with "sqlReport.SQL.Add('<<sql here>>');" (takes about 5 minutes depending on the query size)

4) Change any occurences of ' to ''

5) Add all of the optional filters in the "where" clause based on the user input in the form.

Ofcourse hardly anything is every correct first time, so I have to go back to IBConsole, rework my query, repaste the command, wrap it up with Delphi code, you get the picture.

There is a saying that necessity is the mother of invention. Well, after manually converting multiple lines of SQL to Delphi code a number of times I started to feel the "necessity" for a better solution. Luckily I talk to Jacob quite often, and during the course of complaining about how I hate doing this kind of repetitive task it occurred to me, maybe Jacob could write something into Castalia which would do the trick?

Well, the outcome of the conversation was the Multi paste option. This cleverly concealed feature of Castalia hides away under the Edit menu. It takes two strings, the first tells Castalia what text you want to appear at the start of each line in the clipboard, and the second tells it what text you want to appear at the end of each line in the clipboard. Now my routine looks like this

1) Work out the SQL in IBConsole

2) Select multi-paste and tell it what to wrap my code with

3) Add all of the optional filters in the "where" clause based on the user input in the form.

Step 2 now takes a split second instead of 5 minutes a time. What I really love though is that Castalia is really smart about how it performs this "multi paste". Not only does it perform the addition of the wrapping code to each line, it also provides you with the option to escape single quotes (change ' to '') just incase you are wrapping the text into a string. If that's not all, it automatically indents the pasted text to your current cursor position AND you can even see a preview of the pasted text as you type in the "text before" and "text after" values, just to ensure that your pasted code is going to compile.

I must say, that this option turned out much better than I had originally hoped. I use this feature all of the time, and it saves me a lot of repetitive work.

This Tip of the Day was written by Peter Morris (to give you a break from Jacob's writing).  Peter is a self-employed software developer, consultant, writer, and lecturer. Peter owns droopyeyes.com, a VCL components site, and howtodothings.com, where you can find information on just about anything.

Copyright ©2008 TwoDesk Software Company. All Rights Reserved.