Delphi
Basics
 
Delphi Basics hints and tips
 
The idea of this page is to collect together in one place small, but eminently useful aids to efficient and productive programming in Delphi.

This list will start small, and grow with just the best hints and tips. Alternatively, you can look in Delphi help - for example, type in Shortcuts in the Find tab.

Feel free to contact the author to add to the list here - your suggestions are more than welcome.

This page has been translated into Spanish here by Maria Ramos from Webhostinghub.com

 
Editor shortcuts

Shortcut KeysResulting actions

Alt + BlockSelect Allows column constrained selection of a text block.

Normally, when you select more than one line using the mouse (by dragging with the left mouse button down) or the arrow keys (with shift held down), the text on the middle lines is always the whole line.

By holding down the Alt key before doing starting the selection, you mark just a vertical block of text. (You can release the Alt key as soon as you have started marking).

When you insert the copied block, it will insert the text where the cursor is positioned, but will not create new lines. It effectively inserts horizontally, but not vertically. The best way to see the effect is to try it!

Ctrl + Shift + i Block Indent. Indents a block of text (lines or Alt-selection) by the tab amount.

Ctrl + Shit + u Block UnIndent. UnIndents a block of text (lines or Alt-selection) by the tab amount.

Ctrl + Shift
+ UpArrow
Switch between routine definition and implementation.

Position the cursor on the line of a function or procedure in the interface part of your unit, and this key combination will move to the implementation. And vice versa.

Ctrl + Shift + c Code completion

Position the cursor at a new function or procedure definition, and this key combination will create the code skeleton, and move the cursor into the begin block ready for typing.

Ctrl + Shift + r Macro record

Records the subsequent mouse and key actions as a macro. Finish with the same key combination.

Ctrl + Shift + p Macro play

Plays the last recorded macro.

Ctrl + e Incremental search. The letters you subsequently type form a search string. As you type, it moves to the first part of the current file that matches the string.

It is not case sensitive. Press Escape to stop searching.

Miscellaneous tips

Shortcut in the Mozilla browser

The Mozilla browser provides bookmarks with a nice feature - you can access a bookmarked site by typing in the shortcut name for the bookmark. The defining feature of these bookmarks is that they provide parameter passing.

You can set up a bookmark that lets you type in the following :

d Array will take you to http://www.delphibasics.co.uk/RTL.asp?Name=Array

d Inc will take you to http://www.delphibasics.co.uk/RTL.asp?Name=Inc

To set up such a bookmark, do the following :

  1. Navigate to http://www.delphibasics.co.uk/RTL.asp?Name=Array in the browser.
  2. Bookmark this page
  3. Go to the Bookmarks|Manage Bookmarks and Properties menu item for this bookmark
  4. Change the location to http://www.delphibasics.co.uk/RTL.asp?Name=%s (note the %s)
  5. Type d in the keyword field
  6. Finished!
Shortcut in Internet Explorer

Thanks to Stuart Eggerton for the following tip (who in turn thanks http://www.kellys-korner-xp.com for the google example used as the basis for the idea).

Whilst IE does not have the nice Mozilla bookmarks feature, by adding registry entries for IE, you can provide the same functionailty.

Copy the following text into a file with vbs extension. Double click it to execute it and thereby add registry entries for IE:

Option Explicit

Set ws = WScript.CreateObject("WScript.Shell")
Dim ws, n, p, itemtype, MyBox, Title, vbdefaultbutton

p = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchUrl\d\"
itemtype = "REG_SZ"
n = "http://www.delphibasics.co.uk/RTL.asp?Name=%s"

Ws.RegWrite p, n, itemtype

p = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchUrl\d\ "
itemtype = "REG_SZ"
n = "+"

Ws.RegWrite p, n, itemtype

p = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchUrl\d\%"
itemtype = "REG_SZ"
n = "%25"

Ws.RegWrite p, n, itemtype

p = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchUrl\d\&"
itemtype = "REG_SZ"
n = "%26"

Ws.RegWrite p, n, itemtype

p = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchUrl\d\+"
itemtype = "REG_SZ"
n = "%2B"

Ws.RegWrite p, n, itemtype

Title = "To use, type in: d followed by a space then the search term."
MyBox = MsgBox(Title,4096,"Quick access to Delphi Basics from the Address Bar")

d Array will take you to http://www.delphibasics.co.uk/RTL.asp?Name=Array

d Inc will take you to http://www.delphibasics.co.uk/RTL.asp?Name=Inc

Using frames when making lots of forms

To create a frame, you must use the File|New Frame menu option (the Frames component on the Standard tab merely gives you access to the list of frames defined in the current project).

A frame is like a form - you can add components to it in the same way. The power comes when you start creating the forms of your application - you can drop in a frame into a form, and all the form components are there as you defined them in the frame. Except that you can move them and change them to suit each frame (but you cannot add components). The frame provides a skeleton.

If you change a component in the frame, all forms using the frame will have the component changed to suit - the frame skeleton dynamically affects the forms based on it.

Web applications

To make sure your web applications run smoothly, find a web hosting provider that meets your programming needs.

A final hint: Remember to take a break from your work. Get some fresh air on the patio or just relax in your garden furniture. All work and no play makes Jack a dull boy!

 
Neil Moffatt 2002 - 2012. All rights reserved.  |  Contact the author