MultiPaste in the RAD Studio IDE

Late last year I had the honor of speaking with Cary Jensen at the Delphi Developer Days events. It was a great opportunity to meet some new folks, folks I’ve known online for years, and to present some useful information about Delphi.

One of the presentations we gave was entitled “Delphi Tips, Tricks, and Techniques”.  We showed a bunch of cool shortcuts and other things. It was fun and well received.

So we were in Copenhagen for our second DDD event, and my good friend Jens Fudge comes up to me after I gave my Tips and Tricks and says that I should add MultiPaste to the talk.

Of course, much to my embarrassment, my response was “What is MultiPaste”.  Well, Jens showed me, and now I’m about to show you.  (To make myself look a little better, when I presented MultiPaste in Frankfurt, no one there had heard of it either……)

Okay, so what is MultiPaste?  It’s a feature that came along with the Castalia acquisition, and one that clearly hasn’t had enough attention paid to it.

Ever had a problem like this?  You have some SQL, say:

SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;

and you want to add that SQL to the SQL property of a query at runtime.  You end up either having to turn this into a string like this:

'SELECT Customers.CustomerName, Orders.OrderID' +
'FROM Customers' +
'FULL OUTER JOIN Orders' +
'ON Customers.CustomerID = Orders.CustomerID' +
'ORDER BY Customers.CustomerName;'

or manually in each line like this:

FDQuery1.SQL.Add('SELECT Customers.CustomerName, Orders.OrderID');
FDQuery1.SQL.Add('FROM Customers');
FDQuery1.SQL.Add('FULL OUTER JOIN Orders');
FDQuery1.SQL.Add('ON Customers.CustomerID = Orders.CustomerID');
FDQuery1.SQL.Add('ORDER BY Customers.CustomerName;');

Both choices are a big pain in the butt to code.

But not anymore.  MultiPaste makes this kind of thing pathetically easy!

Let’s choose the second option above — the manual adding of the SQL code one line at a time.

First, copy the SQL to your clipboard.  This is important — the text that you want to manipulate must be on your clipboard.

Next, place your cursor where you want the resulting text to be inserted.

Then, select Edit|MultiPaste  from the IDE’s menu  (You’ll need to have a code window open for the menu item to be active).  You’ll see this:

Now, from there, you can type this in the first edit box:

FDQuery1.SQL.Add('

and then in the second edit box, type:

');

You should then notice that the main memo box is changing the text you have on your clipboard by adding the contents of the first edit box to the beginning of each line, and the contents of the second edit box to the end of each line.  You should end up with a dialog that looks like this:

Then, hit Ok and the text that you created is inserted at the cursor point.   Pretty cool, huh?

Thus, MultiPaste allows you to avoid a bit of the time consuming and tedious coding that we all have done at one time or another.

Just another great feature to make your IDE a bit more productive.

9 Replies to “MultiPaste in the RAD Studio IDE”

  1. 1) This seems like a huge workaround to the simple, obvious need of adding multi-line strings. Heck, the IDE can’t even handle strings greater than 256 characters – an anachronism shared by the Lazarus IDE.

    2) It says something about standard Delphi APIs that there are so many cases where you’re repeating yourself that this kind of thing was added to Castalia. I dub it the “Delphi pattern” for lack of a catchy name. It’s caused by another omission, optional parameters. To compensate, what could just be a function call becomes an object along with lots of properties to set and finally some type of “execute” method (the classic Delphi database API is a good example, another being the REST API).

    By ignoring the fact that “FDQuery1.SQL.ADD” is repeated five times by having the IDE handle the data entry, we’re going the Java route – verbose language that relies on the IDE to compensate. “Just another great feature to make your IDE a bit more productive.” – productivity should come primarily from the language, not the IDE, which is something Java users have been complaining about recently as well.

    Image if Delphi had type inference and multi-line strings, neither very exotic features. The code then becomes:

    var query := ”’SELECT Customers.CustomerName, Orders.OrderID
    FROM Customers
    FULL OUTER JOIN Orders
    ON Customers.CustomerID = Orders.CustomerID
    ORDER BY Customers.CustomerName;”’

    FDQuery1.SQL.Add(query);

    Easier to read, easier to edit, no need for a wizard. While we’re at it, imagine that syntax highlighting works within strings as with the JetBrains IDEs – then the SQL would be syntax highlighted too!

    Now THAT would be pretty cool and some great features to make us more productive. This particular example just makes me feel sad because it doesn’t need to exist in the first place.

  2. Since when this feature is available in Delphi? In XE7 it doesn’t seem to be present. 🙁

  3. Using multiple MyQuery.SQL.Add(‘YOUR SQL HERE’) lines is the *real* anti-pattern. Many DataSet descendants have code attached to SQL’s OnChange event. Some DB frameworks will generate a server request when SQL changes (parameter or field type fetch, etc.). In short, DON’T DO IT!

Comments are closed.