PDA

View Full Version : The best Delphi IDE hints and tips thread in the world!



Alimonster
04-04-2003, 02:46 PM
Here are some tips about the delphi IDE from my own experience. Feel free to chip in with your own tips and/or good practice! Let's make ourselves a lot more productive with one of the nicest tools for programming.

Pressing Esc takes you to the current component's parent if you have one selected. This is especially handy if you currently have a client-aligned component and need its parent.

Press CTRL-SHIFT-I and CTRL-SHIFT-U to indent/outdent the selected text (the value of "block indent" under the environment options controls how far it moves).

When debugging, CTRL-clicking something will open an inspector with that
value (especially handy for structured types to see all its fields).

You can add a .rc resource script to your project to have it compiled + linked to your exe.

Don't forget that there's a "lock controls" option!

When a component is selected on your form, you can use CTRL-left/right/up/down arrow to move the component a pixel in that direction -- handy for oh-so-fine positioning. You can use SHIFT-left/right/up/down arrow to resize it one pixel at a time.

Make sure that you customize the main toolbar! Right click on it and select "customize", then go to the options tab. Drag and drop buttons that you use frequently onto the toolbar -- for example, I think it's a good plan to dump the "Windows SDK Help" button on to it, with the "Close All" button directly beneath.

INSTALL G-Experts (www.gexperts.org) RIGHT NOW!

G-Experts is exceptionally useful -- for example, there's a code-proofreader component that automatically corrects mistakes! For example, if I type ;= then it will automatically change it into := -- yummy! It also lets you change the component palette and object inspector's fonts! Other features are: a todo list (which may be useful if you're using the personal edition of a Delphi w/out this feature), allowing a customizable toolbar on your code editor (which is especially handy if you're using the "zoom to full screen" mode under editor options->display), an ASCII table (which is a small, but very nice feature to have at a menu click!), and some other good stuff. You should install it right now!

Go to your current project's directory -- pretty messy, isn't it, with all those .dcu files? First, create a sub-folder in your current project's directory (e.g. called "temp"). Next, go to Project->Options->Directories/Conditionals. Find the "Unit Output Directory" box (probably second-from-top). Select the temporary folder there. Go to your project directory and get rid of the previous .dcus files. When you rebuild your app, the .dcus will get dumped into the separate sub-folder, which cleans up your project significantly!

Use a convention for __ANY__ idea that comes into your mind in any way! For example, you should get into the habit of using // todo: whatever comments. Use them extensively for anything. If you have an idea, then say // todo: can we do x instead of y here? Leave a trail for yourself, and don't be afraid to go overboard with todos -- you can always delete them later. If you have a bug or possible problem, be sure to comment it __at the time__!

Try docking the project manager to the left or right of your code editor and set it up to be an appropriate width (resize it and scroll it so that only filenames are present). This will give you access to every file you've added to the project. Once you get used to it, it's hard to do without!

CTRL-F12 lets you quickly view a unit in your project.

You can find text quickly using CTRL-E, which performs an incremental search -- Delphi will match any letters you type until it can't no more. F3 to select the next match, as normal. It's like type-ahead find in Mozilla.

Don't forget about the object repository either! Add frequently used project templates to there. Save yourself some time.

CTRL-F7 opens the evaluate/modify dialogue while debugging. LEARN THIS SHORTCUT BY HEART!

Download this font (http://www.ms-studio.com/FontSales/anonymous.html) and copy it into your windows\fonts (or winnt\fonts if applicable) directory. Set the code editor to use it, size 9. It's so gosh-darned clear (especially if you have "smooth fonts" enabled under Windows' display properties). I think it's much better than the standard editor font.

Configure your tools! If you have a task that needs done regularly, whip up a small Delphi app to take care of it. Place it under the Tools menu option w/ "Configure tools" and give it a shortcut. For example, I frequently want to have a look at thumbnails of bitmaps in a directory (e.g. if I want to select a bitbtn's glyph). I simply created a small image viewer (copying and pasting code from the Delphi help, no less) and added it as a tool. Do the same for whatever you need!

There's an align option too -- select many different objects first (either drag-select with the mouse or shift-click). It lets you sort out your layout very easily! You can also take a look at the alignment palette.

Alimonster
06-04-2003, 01:23 PM
A couple more shortcuts:

CTRL-SHIFT-SPACE, when inside a function, displays the function parameters tooltip (most of the time ;)). This is especially handy when Delphi 'forgets' that you want it (e.g. you move the keyboard cursor out of the function for a little while, and then back in).

CTRL-SPACE forces the code insight drop-down list of functions/methods. Again, quite handy.

Traveler
07-04-2003, 08:36 AM
wow thanks! Very usefull :D

Kim Friis
07-04-2003, 08:58 AM
Go to your current project's directory -- pretty messy, isn't it, with all those .dcu files? First, create a sub-folder in your current project's directory (e.g. called "temp"). Next, go to Project->Options->Directories/Conditionals. Find the "Unit Output Directory" box (probably second-from-top). Select the temporary folder there. Go to your project directory and get rid of the previous .dcus files. When you rebuild your app, the .dcus will get dumped into the separate sub-folder, which cleans up your project significantly!

Here I just want to point out, that a good project directory structure could be:

c:\projects\projectname\source for your source files,
c:\projects\projectname\bin for your executable (just point it to ..\bin)
c:\projects\projectname\dcu for your dcu (just point it to ..\dcu)
that way, if you copy the project to another place (or computer), the project settings will still work.

And then I find that if you set, "show component captions" to true in the environment options, then it is easyer to find out what is happening on your datamodules... But that is only if you use non visual components.

Apart from that, it is a VERY good list, where I use most of it every day.

Useless Hacker
07-04-2003, 09:25 AM
I think you missed:

F12 - shows the form associated with the current unit.

Clootie
07-04-2003, 07:20 PM
F12 - Switch between form and code unit :roll:
F11 - Show up ObjectInspector 8)

Xorcist
07-04-2003, 08:51 PM
CTRL-F12 lets you quickly view a unit in your project.



Note that the above will open a seletion box of unit's "open" within the project space. If you want to open a unit that has been included in the unit you are currently viewing (without having to hunt it down on your harddrive), simply move the cursor to the first character of the filename and press CTRL-ENTER. (actually the cursor can be anywhere within the filename and it will work).

Sly
09-04-2003, 12:10 AM
I have to disagree about the choice of font. I tried AnonymousTT and found it much harder to read than Courier New or my favourite, Lucida Console. Note that I use the Twilight colour scheme.